Skip to content

Commit

Permalink
Add smoke test
Browse files Browse the repository at this point in the history
  • Loading branch information
trask committed Mar 8, 2024
1 parent eed0626 commit 6cbc9a1
Show file tree
Hide file tree
Showing 6 changed files with 129 additions and 0 deletions.
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ hideFromDependabot(":smoke-tests:apps:HttpClients")
hideFromDependabot(":smoke-tests:apps:HttpHeaders")
hideFromDependabot(":smoke-tests:apps:HttpPreaggregatedMetrics")
hideFromDependabot(":smoke-tests:apps:HttpServer4xx")
hideFromDependabot(":smoke-tests:apps:HttpServerQueryString")
hideFromDependabot(":smoke-tests:apps:InheritedAttributes")
hideFromDependabot(":smoke-tests:apps:InstrumentationKeyOverrides")
hideFromDependabot(":smoke-tests:apps:JavaProfiler")
Expand Down
11 changes: 11 additions & 0 deletions smoke-tests/apps/HttpServerQueryString/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
plugins {
id("ai.smoke-test-war")
}

dependencies {
implementation("org.springframework.boot:spring-boot-starter-web:2.5.12") {
exclude("org.springframework.boot", "spring-boot-starter-tomcat")
}
// this dependency is needed to make wildfly happy
implementation("org.reactivestreams:reactive-streams:1.0.3")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.microsoft.applicationinsights.smoketestapp;

import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;

@SpringBootApplication
public class SpringBootApp extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) {
return applicationBuilder.sources(SpringBootApp.class);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.microsoft.applicationinsights.smoketestapp;

import javax.servlet.http.HttpServletResponse;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class TestController {

@GetMapping("/")
public String root() {
return "OK";
}

@GetMapping("/test")
public String test(HttpServletResponse response) {
return "OK!";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

package com.microsoft.applicationinsights.smoketest;

import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_11;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_11_OPENJ9;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_17;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_19;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_20;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8_OPENJ9;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8;
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.data.MapEntry.entry;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

@UseAgent
abstract class HttpServerQueryStringTest {

@RegisterExtension static final SmokeTestExtension testing = SmokeTestExtension.create();

@Test
@TargetUri("/test?query")
void queryTest() throws Exception {
Telemetry telemetry = testing.getTelemetry(0);

assertThat(telemetry.rd.getName()).isEqualTo("GET /HttpServerQueryString/test");
assertThat(telemetry.rd.getUrl())
.matches("http://localhost:[0-9]+/HttpServerQueryString/test\\?query");
assertThat(telemetry.rd.getResponseCode()).isEqualTo("200");
assertThat(telemetry.rd.getSuccess()).isTrue();
assertThat(telemetry.rd.getSource()).isNull();
assertThat(telemetry.rd.getProperties())
.containsExactly(entry("_MS.ProcessedByMetricExtractors", "True"));
assertThat(telemetry.rd.getMeasurements()).isEmpty();
}

@Environment(TOMCAT_8_JAVA_8)
static class Tomcat8Java8Test extends HttpServerQueryStringTest {}

@Environment(TOMCAT_8_JAVA_8_OPENJ9)
static class Tomcat8Java8OpenJ9Test extends HttpServerQueryStringTest {}

@Environment(TOMCAT_8_JAVA_11)
static class Tomcat8Java11Test extends HttpServerQueryStringTest {}

@Environment(TOMCAT_8_JAVA_11_OPENJ9)
static class Tomcat8Java11OpenJ9Test extends HttpServerQueryStringTest {}

@Environment(TOMCAT_8_JAVA_17)
static class Tomcat8Java17Test extends HttpServerQueryStringTest {}

@Environment(TOMCAT_8_JAVA_19)
static class Tomcat8Java19Test extends HttpServerQueryStringTest {}

@Environment(TOMCAT_8_JAVA_20)
static class Tomcat8Java20Test extends HttpServerQueryStringTest {}

@Environment(WILDFLY_13_JAVA_8)
static class Wildfly13Java8Test extends HttpServerQueryStringTest {}

@Environment(WILDFLY_13_JAVA_8_OPENJ9)
static class Wildfly13Java8OpenJ9Test extends HttpServerQueryStringTest {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern>
</encoder>
</appender>
<root level="warn">
<appender-ref ref="CONSOLE"/>
</root>
</configuration>

0 comments on commit 6cbc9a1

Please sign in to comment.