|
18 | 18 | import io.opentelemetry.sdk.metrics.View; |
19 | 19 | import java.util.Arrays; |
20 | 20 | import java.util.Collections; |
21 | | -import org.junit.jupiter.api.Test; |
| 21 | +import java.util.stream.Stream; |
| 22 | +import org.junit.jupiter.params.ParameterizedTest; |
| 23 | +import org.junit.jupiter.params.provider.Arguments; |
| 24 | +import org.junit.jupiter.params.provider.MethodSource; |
22 | 25 |
|
23 | 26 | class ViewFactoryTest { |
24 | 27 |
|
25 | | - @Test |
26 | | - void create_Defaults() { |
27 | | - View expectedView = View.builder().build(); |
28 | | - |
29 | | - View view = |
30 | | - ViewFactory.getInstance() |
31 | | - .create( |
32 | | - new ViewStreamModel().withAttributeKeys(null), |
33 | | - mock(DeclarativeConfigContext.class)); |
34 | | - |
| 28 | + @ParameterizedTest |
| 29 | + @MethodSource("createArguments") |
| 30 | + void create(ViewStreamModel model, View expectedView) { |
| 31 | + View view = ViewFactory.getInstance().create(model, mock(DeclarativeConfigContext.class)); |
35 | 32 | assertThat(view.toString()).isEqualTo(expectedView.toString()); |
36 | 33 | } |
37 | 34 |
|
38 | | - @Test |
39 | | - void create() { |
40 | | - View expectedView = |
41 | | - View.builder() |
42 | | - .setName("name") |
43 | | - .setDescription("description") |
44 | | - .setAttributeFilter( |
45 | | - IncludeExcludePredicate.createPatternMatching( |
46 | | - Arrays.asList("foo", "bar"), Collections.singletonList("baz"))) |
47 | | - .setAggregation( |
48 | | - Aggregation.explicitBucketHistogram( |
49 | | - ExplicitBucketHistogramOptions.builder() |
50 | | - .setBucketBoundaries(Arrays.asList(1.0, 2.0)) |
51 | | - .build())) |
52 | | - .build(); |
53 | | - |
54 | | - View view = |
55 | | - ViewFactory.getInstance() |
56 | | - .create( |
57 | | - new ViewStreamModel() |
58 | | - .withName("name") |
59 | | - .withDescription("description") |
60 | | - .withAttributeKeys( |
61 | | - new IncludeExcludeModel() |
62 | | - .withIncluded(Arrays.asList("foo", "bar")) |
63 | | - .withExcluded(Collections.singletonList("baz"))) |
64 | | - .withAggregation( |
65 | | - new AggregationModel() |
66 | | - .withExplicitBucketHistogram( |
67 | | - new ExplicitBucketHistogramAggregationModel() |
68 | | - .withBoundaries(Arrays.asList(1.0, 2.0)))), |
69 | | - mock(DeclarativeConfigContext.class)); |
70 | | - |
71 | | - assertThat(view.toString()).isEqualTo(expectedView.toString()); |
| 35 | + private static Stream<Arguments> createArguments() { |
| 36 | + return Stream.of( |
| 37 | + // defaults |
| 38 | + Arguments.of(new ViewStreamModel().withAttributeKeys(null), View.builder().build()), |
| 39 | + // attribute_keys with only included (no excluded) - reproduces |
| 40 | + // https://github.com/open-telemetry/opentelemetry-java/issues/8337 |
| 41 | + Arguments.of( |
| 42 | + new ViewStreamModel() |
| 43 | + .withAttributeKeys( |
| 44 | + new IncludeExcludeModel() |
| 45 | + .withIncluded( |
| 46 | + Arrays.asList( |
| 47 | + "url.full", "http.request.method", "http.response.status_code"))), |
| 48 | + View.builder() |
| 49 | + .setAttributeFilter( |
| 50 | + IncludeExcludePredicate.createPatternMatching( |
| 51 | + Arrays.asList( |
| 52 | + "url.full", "http.request.method", "http.response.status_code"), |
| 53 | + null)) |
| 54 | + .build()), |
| 55 | + // full configuration |
| 56 | + Arguments.of( |
| 57 | + new ViewStreamModel() |
| 58 | + .withName("name") |
| 59 | + .withDescription("description") |
| 60 | + .withAttributeKeys( |
| 61 | + new IncludeExcludeModel() |
| 62 | + .withIncluded(Arrays.asList("foo", "bar")) |
| 63 | + .withExcluded(Collections.singletonList("baz"))) |
| 64 | + .withAggregation( |
| 65 | + new AggregationModel() |
| 66 | + .withExplicitBucketHistogram( |
| 67 | + new ExplicitBucketHistogramAggregationModel() |
| 68 | + .withBoundaries(Arrays.asList(1.0, 2.0)))), |
| 69 | + View.builder() |
| 70 | + .setName("name") |
| 71 | + .setDescription("description") |
| 72 | + .setAttributeFilter( |
| 73 | + IncludeExcludePredicate.createPatternMatching( |
| 74 | + Arrays.asList("foo", "bar"), Collections.singletonList("baz"))) |
| 75 | + .setAggregation( |
| 76 | + Aggregation.explicitBucketHistogram( |
| 77 | + ExplicitBucketHistogramOptions.builder() |
| 78 | + .setBucketBoundaries(Arrays.asList(1.0, 2.0)) |
| 79 | + .build())) |
| 80 | + .build())); |
72 | 81 | } |
73 | 82 | } |
0 commit comments