/*
 * Copyright The OpenTelemetry Authors
 * SPDX-License-Identifier: Apache-2.0
 */

package io.opentelemetry.sdk.trace.config;

import static org.assertj.core.api.Assertions.assertThat;

import io.opentelemetry.sdk.trace.SpanLimits;
import org.junit.jupiter.api.Test;

class SpanLimitsTest {

  @Test
  void defaultSpanLimits() {
    assertThat(SpanLimits.getDefault().getMaxNumberOfAttributes()).isEqualTo(128);
    assertThat(SpanLimits.getDefault().getMaxNumberOfEvents()).isEqualTo(128);
    assertThat(SpanLimits.getDefault().getMaxNumberOfLinks()).isEqualTo(128);
    assertThat(SpanLimits.getDefault().getMaxNumberOfAttributesPerEvent()).isEqualTo(128);
    assertThat(SpanLimits.getDefault().getMaxNumberOfAttributesPerLink()).isEqualTo(128);
  }

  @Test
  void updateSpanLimits_All() {
    SpanLimits spanLimits =
        SpanLimits.builder()
            .setMaxNumberOfAttributes(8)
            .setMaxNumberOfEvents(10)
            .setMaxNumberOfLinks(11)
            .setMaxNumberOfAttributesPerEvent(1)
            .setMaxNumberOfAttributesPerLink(2)
            .build();
    assertThat(spanLimits.getMaxNumberOfAttributes()).isEqualTo(8);
    assertThat(spanLimits.getMaxNumberOfEvents()).isEqualTo(10);
    assertThat(spanLimits.getMaxNumberOfLinks()).isEqualTo(11);
    assertThat(spanLimits.getMaxNumberOfAttributesPerEvent()).isEqualTo(1);
    assertThat(spanLimits.getMaxNumberOfAttributesPerLink()).isEqualTo(2);

    // Preserves values
    SpanLimits spanLimitsDupe = spanLimits.toBuilder().build();
    // Use reflective comparison to catch when new fields are added.
    assertThat(spanLimitsDupe).usingRecursiveComparison().isEqualTo(spanLimits);
  }
}

@@ -180,16 +180,82 @@
 ertThat;
+%0Aimport static org.assertj.core.api.Assertions.assertThatThrownBy;
 %0A%0Aimport
@@ -1739,11 +1739,1547 @@
 ts);%0A  %7D
+%0A%0A  @Test%0A  void invalidSpanLimits() %7B%0A    assertThatThrownBy(() -%3E SpanLimits.builder().setMaxNumberOfAttributes(0))%0A        .isInstanceOf(IllegalArgumentException.class);%0A    assertThatThrownBy(() -%3E SpanLimits.builder().setMaxNumberOfAttributes(-1))%0A        .isInstanceOf(IllegalArgumentException.class);%0A    assertThatThrownBy(() -%3E SpanLimits.builder().setMaxNumberOfEvents(0))%0A        .isInstanceOf(IllegalArgumentException.class);%0A    assertThatThrownBy(() -%3E SpanLimits.builder().setMaxNumberOfEvents(-1))%0A        .isInstanceOf(IllegalArgumentException.class);%0A    assertThatThrownBy(() -%3E SpanLimits.builder().setMaxNumberOfLinks(0))%0A        .isInstanceOf(IllegalArgumentException.class);%0A    assertThatThrownBy(() -%3E SpanLimits.builder().setMaxNumberOfLinks(-1))%0A        .isInstanceOf(IllegalArgumentException.class);%0A    assertThatThrownBy(() -%3E SpanLimits.builder().setMaxNumberOfAttributesPerEvent(0))%0A        .isInstanceOf(IllegalArgumentException.class);%0A    assertThatThrownBy(() -%3E SpanLimits.builder().setMaxNumberOfAttributesPerEvent(-1))%0A        .isInstanceOf(IllegalArgumentException.class);%0A    assertThatThrownBy(() -%3E SpanLimits.builder().setMaxNumberOfAttributesPerLink(0))%0A        .isInstanceOf(IllegalArgumentException.class);%0A    assertThatThrownBy(() -%3E SpanLimits.builder().setMaxNumberOfAttributesPerLink(-1))%0A        .isInstanceOf(IllegalArgumentException.class);%0A    assertThatThrownBy(() -%3E SpanLimits.builder().setMaxAttributeValueLength(-1))%0A        .isInstanceOf(IllegalArgumentException.class);%0A  %7D
 %0A%7D%0A

Add tests for illegal span limits (#3673)