Search in sources :

Example 11 with AbstractEnvironment

use of org.springframework.core.env.AbstractEnvironment in project Gaffer by gchq.

the class FactoryConfigTest method shouldUsePropertiesFromEnvironmentToSetUpUserFactory.

@Test
public void shouldUsePropertiesFromEnvironmentToSetUpUserFactory() throws InstantiationException, IllegalAccessException {
    // Given
    FactoryConfig factoryConfig = new FactoryConfig();
    AbstractEnvironment mockEnv = mock(AbstractEnvironment.class);
    Properties properties = new Properties();
    properties.setProperty(USER_FACTORY_CLASS, MockUserFactory.class.getName());
    MockPropertySource mockPropertySource = new MockPropertySource(properties);
    MutablePropertySources propertySources = new MutablePropertySources();
    propertySources.addFirst(mockPropertySource);
    when(mockEnv.getPropertySources()).thenReturn(propertySources);
    when(mockEnv.getProperty(USER_FACTORY_CLASS)).then(invocation -> mockPropertySource.getProperty(invocation.getArgumentAt(0, String.class)));
    // called by spring normally
    factoryConfig.setEnvironment(mockEnv);
    // When
    // Called by spring
    factoryConfig.setToSystemProperties();
    // Then
    assertEquals(MockUserFactory.class, factoryConfig.createUserFactory().getClass());
}
Also used : AbstractEnvironment(org.springframework.core.env.AbstractEnvironment) MutablePropertySources(org.springframework.core.env.MutablePropertySources) Properties(java.util.Properties) MockPropertySource(org.springframework.mock.env.MockPropertySource) MockUserFactory(uk.gov.gchq.gaffer.rest.factory.MockUserFactory) Test(org.junit.jupiter.api.Test)

Aggregations

AbstractEnvironment (org.springframework.core.env.AbstractEnvironment)11 MutablePropertySources (org.springframework.core.env.MutablePropertySources)6 Map (java.util.Map)5 Test (org.junit.jupiter.api.Test)4 Function (com.google.common.base.Function)3 FluentIterable (com.google.common.collect.FluentIterable)3 Nullable (javax.annotation.Nullable)3 SparkConf (org.apache.spark.SparkConf)3 Bean (org.springframework.context.annotation.Bean)3 ResourcePropertySource (org.springframework.core.io.support.ResourcePropertySource)3 Arrays (java.util.Arrays)2 Properties (java.util.Properties)2 ConfigurableEnvironment (org.springframework.core.env.ConfigurableEnvironment)2 EnumerablePropertySource (org.springframework.core.env.EnumerablePropertySource)2 Environment (org.springframework.core.env.Environment)2 MapPropertySource (org.springframework.core.env.MapPropertySource)2 StandardEnvironment (org.springframework.core.env.StandardEnvironment)2 MockEnvironment (org.springframework.mock.env.MockEnvironment)2 MockPropertySource (org.springframework.mock.env.MockPropertySource)2 Lists (com.google.common.collect.Lists)1