ZipkinActuatorImporter implements ApplicationContextInitializer<GenericApplicationContext> { @Override public void initialize(GenericApplicationContext context) { ConfigurableEnvironment env = context.getEnvironment(); if ("false".equalsIgnoreCase(env.getProperty(PROPERTY_NAME_ACTUATOR_ENABLED))) { LOG.debug("skipping actuator as it is disabled"); return; } String[] includes = Binder.get(env).bind(PROPERTY_NAME_ACTUATOR_INCLUDE, String[].class).orElse(null); if (includes == null || includes.length == 0) { LOG.debug("no actuator configuration found under path " + PROPERTY_NAME_ACTUATOR_INCLUDE); return; } LOG.debug("attempting to load actuator configuration: " + Arrays.toString(includes)); try { context.registerBean(Class.forName(actuatorImplClass)); } catch (Exception e) { LOG.debug("skipping actuator as implementation is not available", e); return; } for (String include : includes) { try { context.registerBean(Class.forName(include)); } catch (Exception e) { LOG.debug("skipping unloadable actuator config " + include, e); } } } ZipkinActuatorImporter();   ZipkinActuatorImporter(String actuatorImplClass); @Override void initialize(GenericApplicationContext context);  }
@Test public void doesntCrashWhenNoIncludes() { zipkinActuatorImporter.initialize(context); context.refresh(); }
@Test public void configuresInclude() { TestPropertyValues.of( "zipkin.internal.actuator.include[0]=" + Include1.class.getName() ).applyTo(context); zipkinActuatorImporter.initialize(context); context.refresh(); context.getBean(Include1.class); }
@Test public void doesntCrashOnBadActuatorImpl() { TestPropertyValues.of( "zipkin.internal.actuator.include[0]=" + Include1.class.getName() ).applyTo(context); new ZipkinActuatorImporter("tomatoes").initialize(context); context.refresh(); assertThatThrownBy(() -> context.getBean(Include1.class)) .isInstanceOf(NoSuchBeanDefinitionException.class); }
@Test public void skipsWhenDisabled() { TestPropertyValues.of( PROPERTY_NAME_ACTUATOR_ENABLED + "=false", "zipkin.internal.actuator.include[1]=" + Include2.class.getName() ).applyTo(context); zipkinActuatorImporter.initialize(context); context.refresh(); assertThatThrownBy(() -> context.getBean(Include1.class)) .isInstanceOf(NoSuchBeanDefinitionException.class); }
@Test public void doesntCrashWhenBadInclude() { TestPropertyValues.of( "zipkin.internal.actuator.include[0]=tomatoes" ).applyTo(context); zipkinActuatorImporter.initialize(context); context.refresh(); }
@Test public void configuresIncludes() { TestPropertyValues.of( "zipkin.internal.actuator.include[0]=" + Include1.class.getName(), "zipkin.internal.actuator.include[1]=" + Include2.class.getName() ).applyTo(context); zipkinActuatorImporter.initialize(context); context.refresh(); context.getBean(Include1.class); context.getBean(Include2.class); }