Skip to content

Commit 9d7f126

Browse files
authored
snippet injection add smoke test (#2900)
1 parent a388a2d commit 9d7f126

File tree

8 files changed

+156
-0
lines changed

8 files changed

+156
-0
lines changed

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ hideFromDependabot(":smoke-tests:apps:RoleNameOverrides")
132132
hideFromDependabot(":smoke-tests:apps:RuntimeAttach")
133133
hideFromDependabot(":smoke-tests:apps:RuntimeAttachWithDelayedConnectionString")
134134
hideFromDependabot(":smoke-tests:apps:Sampling")
135+
hideFromDependabot(":smoke-tests:apps:SnippetInjection")
135136
hideFromDependabot(":smoke-tests:apps:SamplingOverrides")
136137
hideFromDependabot(":smoke-tests:apps:SamplingOverridesBackCompat")
137138
hideFromDependabot(":smoke-tests:apps:SpringBoot")
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
plugins {
2+
id("ai.smoke-test-war")
3+
}
4+
5+
dependencies {
6+
implementation("org.springframework.boot:spring-boot-starter-web:2.1.7.RELEASE") {
7+
exclude("org.springframework.boot", "spring-boot-starter-tomcat")
8+
}
9+
// this dependency is needed to make wildfly happy
10+
implementation("org.reactivestreams:reactive-streams:1.0.3")
11+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.applicationinsights.smoketestapp;
5+
6+
import org.springframework.boot.autoconfigure.SpringBootApplication;
7+
import org.springframework.boot.builder.SpringApplicationBuilder;
8+
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
9+
10+
@SpringBootApplication
11+
public class SpringBootApp extends SpringBootServletInitializer {
12+
@Override
13+
protected SpringApplicationBuilder configure(SpringApplicationBuilder applicationBuilder) {
14+
return applicationBuilder.sources(SpringBootApp.class);
15+
}
16+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.applicationinsights.smoketestapp;
5+
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.RestController;
8+
import org.springframework.web.servlet.ModelAndView;
9+
10+
@RestController
11+
public class TestController {
12+
13+
@GetMapping("/")
14+
public String root() {
15+
return "OK";
16+
}
17+
18+
@GetMapping("/test")
19+
public ModelAndView getHelloPage() {
20+
ModelAndView mav = new ModelAndView(); // the name of the HTML page
21+
mav.setViewName("test.html");
22+
return mav;
23+
}
24+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
5+
<meta charset="UTF-8">
6+
<title>Hello</title>
7+
<style>
8+
h1 {color:red;}
9+
p {color:blue;}
10+
</style>
11+
</head>
12+
<body>
13+
<h1>h1 s</h1>
14+
<p>hello hello</p>
15+
</body>
16+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
package com.microsoft.applicationinsights.smoketest;
5+
6+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_11;
7+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_11_OPENJ9;
8+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_17;
9+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_19;
10+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_20;
11+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8;
12+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.TOMCAT_8_JAVA_8_OPENJ9;
13+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8;
14+
import static com.microsoft.applicationinsights.smoketest.EnvironmentValue.WILDFLY_13_JAVA_8_OPENJ9;
15+
import static org.assertj.core.api.Assertions.assertThat;
16+
17+
import org.junit.jupiter.api.Test;
18+
import org.junit.jupiter.api.extension.RegisterExtension;
19+
20+
@UseAgent
21+
abstract class SnippetInjectionTest {
22+
@RegisterExtension
23+
static final SmokeTestExtension testing =
24+
SmokeTestExtension.builder().setSelfDiagnosticsLevel("trace").build();
25+
26+
@Test
27+
@TargetUri("/test")
28+
void normalSnippetInjectionTest() throws Exception {
29+
String url = testing.getBaseUrl() + "/test";
30+
String response = HttpHelper.get(url, "");
31+
assertThat(response).contains("script");
32+
}
33+
34+
@Environment(TOMCAT_8_JAVA_8)
35+
static class Tomcat8Java8Test extends SnippetInjectionTest {}
36+
37+
@Environment(TOMCAT_8_JAVA_8_OPENJ9)
38+
static class Tomcat8Java8OpenJ9Test extends SnippetInjectionTest {}
39+
40+
@Environment(TOMCAT_8_JAVA_11)
41+
static class Tomcat8Java11Test extends SnippetInjectionTest {}
42+
43+
@Environment(TOMCAT_8_JAVA_11_OPENJ9)
44+
static class Tomcat8Java11OpenJ9Test extends SnippetInjectionTest {}
45+
46+
@Environment(TOMCAT_8_JAVA_17)
47+
static class Tomcat8Java17Test extends SnippetInjectionTest {}
48+
49+
@Environment(TOMCAT_8_JAVA_19)
50+
static class Tomcat8Java19Test extends SnippetInjectionTest {}
51+
52+
@Environment(TOMCAT_8_JAVA_20)
53+
static class Tomcat8Java20Test extends SnippetInjectionTest {}
54+
55+
@Environment(WILDFLY_13_JAVA_8)
56+
static class Wildfly13Java8Test extends SnippetInjectionTest {}
57+
58+
@Environment(WILDFLY_13_JAVA_8_OPENJ9)
59+
static class Wildfly13Java8OpenJ9Test extends SnippetInjectionTest {}
60+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"connectionString": "InstrumentationKey=00000000-0000-0000-0000-000000000000",
3+
"role": {
4+
"name": "testrolename",
5+
"instance": "testroleinstance"
6+
},
7+
"sampling": {
8+
"percentage": 100
9+
},
10+
"preview": {
11+
"javaScriptSnippet":
12+
{
13+
"enabled": true
14+
}
15+
}
16+
}
17+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<configuration>
3+
<appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
4+
<encoder>
5+
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level %logger{36} - %msg%n</pattern>
6+
</encoder>
7+
</appender>
8+
<root level="warn">
9+
<appender-ref ref="CONSOLE"/>
10+
</root>
11+
</configuration>

0 commit comments

Comments
 (0)