Repository: open-telemetry/opentelemetry-java
File: sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/DeclarativeConfigurationCreateTest.java (Java)

Code before:
                    new ByteArrayInputStream(yaml.getBytes(StandardCharsets.UTF_8))))
        .doesNotThrowAnyException();
  }

  @Test
  void create_ModelCustomizer() {
    OpenTelemetryConfigurationModel model = new OpenTelemetryConfigurationModel();
    model.withFileFormat("0.3");
    model.withTracerProvider(
        new TracerProviderModel()
            .withProcessors(
                Collections.singletonList(
                    new SpanProcessorModel().withAdditionalProperty("test", null))));
    ComponentLoader componentLoader =
        SpiHelper.serviceComponentLoader(DeclarativeConfiguration.class.getClassLoader());
    OpenTelemetrySdk sdk =
        DeclarativeConfiguration.create(
            model,
            new ComponentLoader() {
              @SuppressWarnings("unchecked")
              @Override
              public <T> Iterable<T> load(Class<T> spiClass) {
                if (DeclarativeConfigurationCustomizerProvider.class.equals(spiClass)) {
                  return (Iterable<T>) Collections.singletonList(getCustomizerProvider());
                }
                return componentLoader.load(spiClass);
              }
            });
    assertThat(sdk.toString())
        .contains(
            "resource=Resource{schemaUrl=null, attributes={"
                + "color=\"blue\", "
                + "foo=\"bar\", "
                + "order=\"second\", "
                + "service.name=\"unknown_service:java\", "
                + "shape=\"square\", "
                + "telemetry.sdk.language=\"java\", "
                + "telemetry.sdk.name=\"opentelemetry\", "
                + "telemetry.sdk.version=\"");
  }

  private static DeclarativeConfigurationCustomizerProvider getCustomizerProvider() {
    return provider ->
        provider.addModelCustomizer(
            model -> {
              ResourceModel resource = model.getResource();
              if (resource == null) {
                resource = new ResourceModel();
                model.withResource(resource);
              }
              List<AttributeNameValueModel> attributes = resource.getAttributes();

Review comment (suggestion):
How about we add a real implementation of `DeclarativeCOnfigurationCustomizerProvider` in this package so we can test end to end without any mocks: https://github.com/open-telemetry/opentelemetry-java/tree/main/sdk-extensions/incubator/src/test/java/io/opentelemetry/sdk/extension/incubator/fileconfig/component

Downside is that the customizer code now lives in a different class than the test, but can add a javadoc link to reference the SPI.

Code after:
  void create_ModelCustomizer() {
    OpenTelemetryConfigurationModel model = new OpenTelemetryConfigurationModel();
    model.withFileFormat("0.3");
    model.withTracerProvider(
        new TracerProviderModel()
            .withProcessors(
                Collections.singletonList(
                    new SpanProcessorModel().withAdditionalProperty("test", null))));
    OpenTelemetrySdk sdk =
        DeclarativeConfiguration.create(
            model,
            // customizer is TestDeclarativeConfigurationCustomizerProvider
            SpiHelper.serviceComponentLoader(
                DeclarativeConfigurationCreateTest.class.getClassLoader()));
    assertThat(sdk.toString())
        .contains(
            "resource=Resource{schemaUrl=null, attributes={"
                + "color=\"blue\", "
                + "foo=\"bar\", "
                + "order=\"second\", "
                + "service.name=\"unknown_service:java\", "
                + "shape=\"square\", "
                + "telemetry.sdk.language=\"java\", "
                + "telemetry.sdk.name=\"opentelemetry\", "
                + "telemetry.sdk.version=\"");
  }
}