apply from: "$rootDir/gradle/instrumentation.gradle"
apply plugin: 'org.unbroken-dome.test-sets'

// compiling against 1.11.0, but instrumentation should work against 1.10.33 with varying effects,
// depending on the version's implementation. (i.e. DeleteOptionGroup may have less handlerCounts than
// expected in 1.11.84. Testing against 1.11.0 instead of 1.10.33 because the RequestHandler class
// used in testing is abstract in 1.10.33
// keeping base test version on 1.11.0 because RequestHandler2 is abstract in 1.10.33,
// therefore keeping base version as 1.11.0 even though the instrumentation probably
// is able to support up to 1.10.33
muzzle {
  pass {
    group = "com.amazonaws"
    module = "aws-java-sdk-core"
    versions = "[1.10.33,)"
    assertInverse = true
  }
}

testSets {
  // Features used in test_1_11_106 (builder) is available since 1.11.84, but
  // using 1.11.106 because of previous concerns with byte code differences
  // in 1.11.106, also, the DeleteOptionGroup request generates more spans
  // in 1.11.106 than 1.11.84.
  // We test older version in separate test set to test newer version and latest deps in the 'default'
  // test dir. Otherwise we get strange warnings in Idea.
  test_before_1_11_106 {
    filter {
      // this is needed because "test.dependsOn test_before_1_11_106", and so without this,
      // running a single test in the default test set will fail
      setFailOnNoMatchingTests(false)
    }
  }
}

configurations {
  test_before_1_11_106RuntimeClasspath {
    resolutionStrategy.force 'com.amazonaws:aws-java-sdk-s3:1.11.0'
    resolutionStrategy.force 'com.amazonaws:aws-java-sdk-rds:1.11.0'
    resolutionStrategy.force 'com.amazonaws:aws-java-sdk-ec2:1.11.0'
    resolutionStrategy.force 'com.amazonaws:aws-java-sdk-kinesis:1.11.0'
    resolutionStrategy.force 'com.amazonaws:aws-java-sdk-sqs:1.11.0'
    resolutionStrategy.force 'com.amazonaws:aws-java-sdk-dynamodb:1.11.0'
  }
}

dependencies {
  compileOnly deps.opentelemetryExtAws

  library group: 'com.amazonaws', name: 'aws-java-sdk-core', version: '1.11.0'

  compileOnly group: 'com.amazonaws', name: 'aws-java-sdk-sqs', version: '1.11.106'

  // Include httpclient instrumentation for testing because it is a dependency for aws-sdk.
  testInstrumentation project(':instrumentation:apache-httpclient:apache-httpclient-4.0:javaagent')
  testLibrary group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.11.106'
  testLibrary group: 'com.amazonaws', name: 'aws-java-sdk-rds', version: '1.11.106'
  testLibrary group: 'com.amazonaws', name: 'aws-java-sdk-ec2', version: '1.11.106'
  testLibrary group: 'com.amazonaws', name: 'aws-java-sdk-kinesis', version: '1.11.106'
  testLibrary group: 'com.amazonaws', name: 'aws-java-sdk-dynamodb', version: '1.11.106'
  testLibrary group: 'com.amazonaws', name: 'aws-java-sdk-sqs', version: '1.11.106'

  // Make sure doesn't add HTTP headers
  testInstrumentation project(':instrumentation:apache-httpclient:apache-httpclient-4.0:javaagent')

  // needed for kinesis:
  testImplementation group: 'com.fasterxml.jackson.dataformat', name: 'jackson-dataformat-cbor', version: versions.jackson

  // needed for SQS - using emq directly as localstack references emq v0.15.7 ie WITHOUT AWS trace header propagation
  testLibrary group: 'org.elasticmq', name: 'elasticmq-rest-sqs_2.12', version: '1.0.0'

  test_before_1_11_106Implementation(group: 'com.amazonaws', name: 'aws-java-sdk-s3', version: '1.11.0')
  test_before_1_11_106Implementation(group: 'com.amazonaws', name: 'aws-java-sdk-rds', version: '1.11.0')
  test_before_1_11_106Implementation(group: 'com.amazonaws', name: 'aws-java-sdk-ec2', version: '1.11.0')
  test_before_1_11_106Implementation(group: 'com.amazonaws', name: 'aws-java-sdk-kinesis', version: '1.11.0')
  test_before_1_11_106Implementation(group: 'com.amazonaws', name: 'aws-java-sdk-sqs', version: '1.11.0')
  test_before_1_11_106Implementation(group: 'com.amazonaws', name: 'aws-java-sdk-dynamodb', version: '1.11.0')
}

test {
  systemProperty "testLatestDeps", testLatestDeps
}

if (!testLatestDeps) {
  test.dependsOn test_before_1_11_106
}
