@Test public void createServices() throws Exception { this.context = new AnnotationConfigApplicationContext( MetricRepositoryAutoConfiguration.class); GaugeService gaugeService = this.context.getBean(BufferGaugeService.class); assertThat(gaugeService).isNotNull(); assertThat(this.context.getBean(BufferCounterService.class)).isNotNull(); assertThat(this.context.getBean(PrefixMetricReader.class)).isNotNull(); gaugeService.submit("foo", 2.7); MetricReader bean = this.context.getBean(MetricReader.class); assertThat(bean.findOne("gauge.foo").getValue()).isEqualTo(2.7); }
@Test public void skipsIfBeansExist() throws Exception { this.context = new AnnotationConfigApplicationContext(Config.class, MetricRepositoryAutoConfiguration.class); assertThat(this.context.getBeansOfType(BufferGaugeService.class)).isEmpty(); assertThat(this.context.getBeansOfType(BufferCounterService.class)).isEmpty(); }
@Test public void createServices() throws Exception { this.context = new AnnotationConfigApplicationContext( MetricRepositoryAutoConfiguration.class); GaugeService gaugeService = this.context.getBean(BufferGaugeService.class); assertNotNull(gaugeService); assertNotNull(this.context.getBean(BufferCounterService.class)); assertNotNull(this.context.getBean(PrefixMetricReader.class)); gaugeService.submit("foo", 2.7); assertEquals(2.7, this.context.getBean(MetricReader.class).findOne("gauge.foo").getValue()); }
@Test public void skipsIfBeansExist() throws Exception { this.context = new AnnotationConfigApplicationContext(Config.class, MetricRepositoryAutoConfiguration.class); assertThat(this.context.getBeansOfType(BufferGaugeService.class).size(), equalTo(0)); assertThat(this.context.getBeansOfType(BufferCounterService.class).size(), equalTo(0)); }
@Bean @ConditionalOnMissingBean(GaugeService.class) public BufferGaugeService gaugeService(GaugeBuffers writer) { return new BufferGaugeService(writer); }