@Bean public MicroserverEnvironment microserverEnvironment(@Qualifier("propertyFactory") Properties props) { if (modules == null) { return new MicroserverEnvironment(props); } return new MicroserverEnvironment(props, modules); }
@Test public void testDefaultHost() throws UnknownHostException { String host =InetAddress.getLocalHost().getHostName(); MicroserverEnvironment microserverEnvironment = new MicroserverEnvironment(new Properties()); microserverEnvironment.assureModule(() ->"context"); assertThat(microserverEnvironment.getModuleBean(()-> "context").getHost(), is(host)); } @Test
@Test public void testDefaultHostNotNull() throws UnknownHostException { MicroserverEnvironment microserverEnvironment = new MicroserverEnvironment(new Properties()); microserverEnvironment.assureModule(() ->"context"); assertThat(microserverEnvironment.getModuleBean(()-> "context").getHost(), is(not(nullValue()))); } @Test
@Test public void testHostOverride() throws UnknownHostException { Properties props = new Properties(); props.put("context.host", "overriden-host"); MicroserverEnvironment microserverEnvironment = new MicroserverEnvironment(props); microserverEnvironment.assureModule(() ->"context"); assertThat(microserverEnvironment.getModuleBean(()-> "context").getHost(), is("overriden-host")); } }
@Test public void testGetModuleBean() { MicroserverEnvironment microserverEnvironment = new MicroserverEnvironment(new Properties(), Arrays.asList(new ModuleBean(8081, "host1", () -> "test"))); assertThat(microserverEnvironment.getModuleBean(()-> "test").getPort(), is(8081)); } @Test
@Test public void testDefaultPort() { MicroserverEnvironment microserverEnvironment = new MicroserverEnvironment(new Properties()); microserverEnvironment.assureModule(() ->"context"); assertThat(microserverEnvironment.getModuleBean(()-> "context").getPort(), is(8080)); }
@Test public void testGetModuleBeanOverridePort() { Properties props = new Properties(); props.put("context.port", 8081); MicroserverEnvironment microserverEnvironment = new MicroserverEnvironment(props); microserverEnvironment.assureModule(() ->"context"); assertThat(microserverEnvironment.getModuleBean(()-> "context").getPort(), is(8081)); }
@Bean public MicroserverEnvironment microserverEnvironment(@Qualifier("propertyFactory") Properties props) { if (modules == null) { return new MicroserverEnvironment(props); } return new MicroserverEnvironment(props, modules); }