Package org.springframework.mock.env

Examples of org.springframework.mock.env.MockEnvironment


    final String defaultHostname = RuntimeUtils.getHost();

    final String customIp = "";
    final String customHostname = "";

    MockEnvironment environment = new MockEnvironment();
    environment.setProperty(CONTAINER_IP_KEY, customIp);
    environment.setProperty(CONTAINER_HOST_KEY, customHostname);

    final ContainerServerApplication containerServerApplication = new ContainerServerApplication();
    containerServerApplication.setEnvironment(environment);

    final ContainerAttributes containerAttributes = containerServerApplication.containerAttributes();
View Full Code Here


  @Test
  public void renderWithReplacement() throws Exception {
    Resource resource = new ByteArrayResource(
        "banner ${a} ${spring-boot.version} ${application.version}".getBytes());
    ResourceBanner banner = new ResourceBanner(resource);
    ConfigurableEnvironment environment = new MockEnvironment();
    Map<String, Object> source = Collections.<String, Object> singletonMap("a", "1");
    environment.getPropertySources().addLast(new MapPropertySource("map", source));
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    banner.printBanner(environment, getClass(), new PrintStream(out));
    assertThat(out.toString(), startsWith("banner 1"));
    assertThat(out.toString(), not(containsString("$")));
  }
View Full Code Here

    }
  }

  @Test
  public void testSuccessfulValidationWithJSR303() {
    MockEnvironment env = new MockEnvironment();
    env.setProperty("test.foo", "123456");
    env.setProperty("test.bar", "654321");
    this.context = new AnnotationConfigApplicationContext();
    this.context.setEnvironment(env);
    this.context.register(TestConfigurationWithJSR303.class);
    this.context.refresh();
  }
View Full Code Here

    this.context.refresh();
  }

  @Test
  public void testInitializersSeeBoundProperties() {
    MockEnvironment env = new MockEnvironment();
    env.setProperty("bar", "foo");
    this.context = new AnnotationConfigApplicationContext();
    this.context.setEnvironment(env);
    this.context.register(TestConfigurationWithInitializer.class);
    this.context.refresh();
  }
View Full Code Here

    assertNotNull(this.context.getBean(MBeanExporter.class));
  }

  @Test
  public void testEnabledMBeanExport() {
    MockEnvironment env = new MockEnvironment();
    env.setProperty("spring.jmx.enabled", "true");
    this.context = new AnnotationConfigApplicationContext();
    this.context.setEnvironment(env);
    this.context.register(JmxAutoConfiguration.class);
    this.context.refresh();
View Full Code Here

    assertNotNull(this.context.getBean(MBeanExporter.class));
  }

  @Test(expected = NoSuchBeanDefinitionException.class)
  public void testDisabledMBeanExport() {
    MockEnvironment env = new MockEnvironment();
    env.setProperty("spring.jmx.enabled", "false");
    this.context = new AnnotationConfigApplicationContext();
    this.context.setEnvironment(env);
    this.context.register(TestConfiguration.class, JmxAutoConfiguration.class);
    this.context.refresh();
View Full Code Here

    this.context.getBean(MBeanExporter.class);
  }

  @Test
  public void testDefaultDomainConfiguredOnMBeanExport() {
    MockEnvironment env = new MockEnvironment();
    env.setProperty("spring.jmx.enabled", "true");
    env.setProperty("spring.jmx.default_domain", "my-test-domain");
    this.context = new AnnotationConfigApplicationContext();
    this.context.setEnvironment(env);
    this.context.register(TestConfiguration.class, JmxAutoConfiguration.class);
    this.context.refresh();
View Full Code Here

        .queryNames(getObjectName("*", "*,*", this.context), null).isEmpty());
  }

  @Test(expected = NoSuchBeanDefinitionException.class)
  public void testEndpointMBeanExporterIsNotInstalled() {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("endpoints.jmx.enabled", "false");
    this.context = new AnnotationConfigApplicationContext();
    this.context.setEnvironment(environment);
    this.context.register(JmxAutoConfiguration.class,
        EndpointAutoConfiguration.class,
        EndpointMBeanExportAutoConfiguration.class);
View Full Code Here

  }

  @Test
  public void testEndpointMBeanExporterWithProperties() throws IntrospectionException,
      InstanceNotFoundException, MalformedObjectNameException, ReflectionException {
    MockEnvironment environment = new MockEnvironment();
    environment.setProperty("endpoints.jmx.domain", "test-domain");
    environment.setProperty("endpoints.jmx.unique_names", "true");
    environment.setProperty("endpoints.jmx.static_names", "key1=value1, key2=value2");
    this.context = new AnnotationConfigApplicationContext();
    this.context.setEnvironment(environment);
    this.context.register(JmxAutoConfiguration.class,
        EndpointAutoConfiguration.class,
        EndpointMBeanExportAutoConfiguration.class);
View Full Code Here

    assertEquals("role1, role2", p.get("crash.auth.spring.roles"));
  }

  @Test
  public void testCustomShellProperties() throws Exception {
    MockEnvironment env = new MockEnvironment();
    env.setProperty("shell.auth", "simple");
    AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext();
    context.setEnvironment(env);
    context.setServletContext(new MockServletContext());
    context.register(TestShellConfiguration.class);
    context.register(CrshAutoConfiguration.class);
View Full Code Here

TOP

Related Classes of org.springframework.mock.env.MockEnvironment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.