@Test public void testInfoEndpointOrdering() throws Exception { this.context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "info.name:foo"); this.context.register(CustomInfoContributorsConfig.class, ProjectInfoAutoConfiguration.class, InfoContributorAutoConfiguration.class, EndpointAutoConfiguration.class); this.context.refresh(); InfoEndpoint endpoint = this.context.getBean(InfoEndpoint.class); Map<String, Object> info = endpoint.invoke(); assertThat(info).isNotNull(); assertThat(info.get("name")).isEqualTo("foo"); assertThat(info.get("version")).isEqualTo("1.0"); Object git = info.get("git"); assertThat(git).isInstanceOf(Map.class); }
@Parameters(name = "{0}") public static Object[] parameters() { return new Object[] { new Object[] { "actuator", HalJsonMvcEndpoint.class }, new Object[] { "autoconfig", AutoConfigurationReportEndpoint.class }, new Object[] { "beans", BeansEndpoint.class }, new Object[] { "configprops", ConfigurationPropertiesReportEndpoint.class }, new Object[] { "docs", DocsMvcEndpoint.class }, new Object[] { "dump", DumpEndpoint.class }, new Object[] { "env", EnvironmentMvcEndpoint.class }, new Object[] { "flyway", FlywayEndpoint.class }, new Object[] { "health", HealthMvcEndpoint.class }, new Object[] { "info", InfoEndpoint.class }, new Object[] { "jolokia", JolokiaMvcEndpoint.class }, new Object[] { "liquibase", LiquibaseEndpoint.class }, new Object[] { "logfile", LogFileMvcEndpoint.class }, new Object[] { "mappings", RequestMappingEndpoint.class }, new Object[] { "metrics", MetricsMvcEndpoint.class }, new Object[] { "shutdown", ShutdownEndpoint.class }, new Object[] { "trace", TraceEndpoint.class } }; }
@Bean public InfoEndpoint infoEndpoint() throws Exception { LinkedHashMap<String, Object> info = new LinkedHashMap<String, Object>(); for (String filename : getAllPropertiesFiles()) { Resource resource = new ClassPathResource("/" + filename); Properties properties = new Properties(); if (resource.exists()) { properties = PropertiesLoaderUtils.loadProperties(resource); String name = resource.getFilename(); info.put(name.replace(PROPERTIES_SUFFIX, PROPERTIES_SUFFIX_REPLACEMENT), Maps.fromProperties(properties)); } else { if (failWhenResourceNotExists()) { throw new RuntimeException("Resource : " + filename + " does not exist"); } else { log.info("Resource {} does not exist", filename); } } } return new InfoEndpoint(info); }
@Test public void endpoints() throws Exception { load(EndpointAutoConfiguration.class); assertThat(this.context.getBean(BeansEndpoint.class)).isNotNull(); assertThat(this.context.getBean(DumpEndpoint.class)).isNotNull(); assertThat(this.context.getBean(EnvironmentEndpoint.class)).isNotNull(); assertThat(this.context.getBean(HealthEndpoint.class)).isNotNull(); assertThat(this.context.getBean(InfoEndpoint.class)).isNotNull(); assertThat(this.context.getBean(MetricsEndpoint.class)).isNotNull(); assertThat(this.context.getBean(ShutdownEndpoint.class)).isNotNull(); assertThat(this.context.getBean(TraceEndpoint.class)).isNotNull(); assertThat(this.context.getBean(RequestMappingEndpoint.class)).isNotNull(); }
@Test public void testInfoEndpoint() throws Exception { this.context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "info.foo:bar"); this.context.register(ProjectInfoAutoConfiguration.class, InfoContributorAutoConfiguration.class, EndpointAutoConfiguration.class); this.context.refresh(); InfoEndpoint endpoint = this.context.getBean(InfoEndpoint.class); assertThat(endpoint).isNotNull(); assertThat(endpoint.invoke().get("git")).isNotNull(); assertThat(endpoint.invoke().get("foo")).isEqualTo("bar"); }
@Test public void testInfoEndpointNoGitProperties() throws Exception { this.context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "spring.info.git.location:classpath:nonexistent"); this.context.register(InfoContributorAutoConfiguration.class, EndpointAutoConfiguration.class); this.context.refresh(); InfoEndpoint endpoint = this.context.getBean(InfoEndpoint.class); assertThat(endpoint).isNotNull(); assertThat(endpoint.invoke().get("git")).isNull(); }
@Bean @ConditionalOnMissingBean public InfoEndpoint infoEndpoint() throws Exception { LinkedHashMap<String, Object> info = new LinkedHashMap<String, Object>(); info.putAll(this.properties.infoMap()); GitInfo gitInfo = this.properties.gitInfo(); if (gitInfo.getBranch() != null) { info.put("git", gitInfo); } return new InfoEndpoint(info); }
@Test public void endpoints() throws Exception { load(EndpointAutoConfiguration.class); assertNotNull(this.context.getBean(BeansEndpoint.class)); assertNotNull(this.context.getBean(DumpEndpoint.class)); assertNotNull(this.context.getBean(EnvironmentEndpoint.class)); assertNotNull(this.context.getBean(HealthEndpoint.class)); assertNotNull(this.context.getBean(InfoEndpoint.class)); assertNotNull(this.context.getBean(MetricsEndpoint.class)); assertNotNull(this.context.getBean(ShutdownEndpoint.class)); assertNotNull(this.context.getBean(TraceEndpoint.class)); assertNotNull(this.context.getBean(RequestMappingEndpoint.class)); }
@Test public void testInfoEndpointConfiguration() throws Exception { this.context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "info.foo:bar"); this.context.register(EndpointAutoConfiguration.class); this.context.refresh(); InfoEndpoint endpoint = this.context.getBean(InfoEndpoint.class); assertNotNull(endpoint); assertNotNull(endpoint.invoke().get("git")); assertEquals("bar", endpoint.invoke().get("foo")); }
@Test public void testNoGitProperties() throws Exception { this.context = new AnnotationConfigApplicationContext(); EnvironmentTestUtils.addEnvironment(this.context, "spring.git.properties:classpath:nonexistent"); this.context.register(EndpointAutoConfiguration.class); this.context.refresh(); InfoEndpoint endpoint = this.context.getBean(InfoEndpoint.class); assertNotNull(endpoint); assertNull(endpoint.invoke().get("git")); }
@Bean @ConditionalOnMissingBean public InfoEndpoint infoEndpoint() throws Exception { return new InfoEndpoint(this.infoContributors == null ? Collections.<InfoContributor>emptyList() : this.infoContributors); }
@Before public void setUp() { this.context.getBean(InfoEndpoint.class).setEnabled(true); this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build(); }
@Bean public InfoEndpoint endpoint() { return new InfoEndpoint(Arrays.asList(beanName1(), beanName2())); }
@Bean public InfoEndpoint endpoint() { return new InfoEndpoint(Collections.<InfoContributor>emptyList()); }
@Bean @Autowired public EndpointMvcAdapter infoMvcEndPoint(InfoEndpoint delegate) { return new EndpointMvcAdapter(delegate); }