Skip to content

Commit d16ea1a

Browse files
authored
Merge pull request #7 from DevSecOpsSamples/add-unit-test
Add unit test
2 parents 05f039c + 3b90cad commit d16ea1a

25 files changed

+62
-37
lines changed

.github/workflows/build.yml

+8-2
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,26 @@ jobs:
1818
uses: actions/setup-java@v1
1919
with:
2020
java-version: 11
21+
2122
- name: Cache SonarCloud packages
2223
uses: actions/cache@v1
2324
with:
2425
path: ~/.sonar/cache
2526
key: ${{ runner.os }}-sonar
2627
restore-keys: ${{ runner.os }}-sonar
28+
2729
- name: Cache Gradle packages
2830
uses: actions/cache@v1
2931
with:
3032
path: ~/.gradle/caches
3133
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
3234
restore-keys: ${{ runner.os }}-gradle
33-
- name: Build and analyze
35+
36+
- name: Build and Test
37+
run: ./gradlew build test
38+
39+
- name: Sonarqube
3440
env:
3541
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
3642
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
37-
run: ./gradlew build sonarqube --info
43+
run: ./gradlew sonarqube --info
Binary file not shown.
Binary file not shown.
-1 Bytes
Binary file not shown.
-19 KB
Binary file not shown.
-17 Bytes
Binary file not shown.

.gradle/6.8.3/gc.properties

Whitespace-only changes.
-4.33 MB
Binary file not shown.
-17 Bytes
Binary file not shown.
-24.9 KB
Binary file not shown.
-17 Bytes
Binary file not shown.

.gradle/buildOutputCleanup/cache.properties

-2
This file was deleted.
-18.8 KB
Binary file not shown.

.gradle/checksums/checksums.lock

-17 Bytes
Binary file not shown.

.gradle/checksums/md5-checksums.bin

-22.3 KB
Binary file not shown.

.gradle/checksums/sha1-checksums.bin

-28.9 KB
Binary file not shown.

.gradle/configuration-cache/gc.properties

Whitespace-only changes.

.gradle/vcs-1/gc.properties

Whitespace-only changes.

bin/main/application.yaml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
813 Bytes
Binary file not shown.
1.81 KB
Binary file not shown.

build.gradle

-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,6 @@ sonarqube {
3434
// property "sonar.host.url", "http://127.0.0.1:9000"
3535
property "sonar.host.url", "https://sonarcloud.io"
3636
property "sonar.sourceEncoding", "UTF-8"
37-
property "sonar.sources", "."
38-
property "sonar.java.binaries", "build"
3937
property "sonar.exclusions", "**/node_modules/**, **/cdk.out/**"
4038
property "sonar.issue.ignore.multicriteria", "e1"
4139
property "sonar.issue.ignore.multicriteria.e1.ruleKey", "typescript:S1848"

src/main/java/com/sec/sample/DemoApplication.java

-12
This file was deleted.

src/main/java/com/sec/sample/SampleController.java

-19
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package com.sample;
2+
3+
import org.junit.jupiter.api.Test;
4+
import org.junit.jupiter.api.Assertions;
5+
import org.springframework.boot.test.context.SpringBootTest;
6+
import org.springframework.beans.factory.annotation.Autowired;
7+
import org.springframework.boot.test.web.client.TestRestTemplate;
8+
import org.springframework.http.ResponseEntity;
9+
import org.springframework.http.HttpStatus;
10+
import org.springframework.test.context.ActiveProfiles;
11+
12+
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
13+
@ActiveProfiles("test")
14+
public class SampleControllerTest {
15+
16+
@Autowired
17+
private TestRestTemplate restTemplate;
18+
19+
@Test
20+
public void testHome() {
21+
ResponseEntity<String> response = restTemplate.getForEntity("/", String.class);
22+
Assertions.assertEquals(HttpStatus.OK, response.getStatusCode());
23+
Assertions.assertEquals("OK", response.getBody());
24+
}
25+
26+
@Test
27+
public void testPingPath1() {
28+
ResponseEntity<String> response = restTemplate.getForEntity("/sample", String.class);
29+
Assertions.assertEquals(HttpStatus.OK, response.getStatusCode());
30+
Assertions.assertEquals("OK", response.getBody());
31+
}
32+
33+
@Test
34+
public void testPingPath2() {
35+
ResponseEntity<String> response = restTemplate.getForEntity("/sample/test1", String.class);
36+
Assertions.assertEquals(HttpStatus.OK, response.getStatusCode());
37+
Assertions.assertEquals("OK", response.getBody());
38+
}
39+
40+
@Test
41+
public void testPingPath3() {
42+
ResponseEntity<String> response = restTemplate.getForEntity("/sample/test1/test2", String.class);
43+
Assertions.assertEquals(HttpStatus.OK, response.getStatusCode());
44+
Assertions.assertEquals("OK", response.getBody());
45+
}
46+
47+
@Test
48+
public void testPingPath4() {
49+
ResponseEntity<String> response = restTemplate.getForEntity("/sample/test1/test2/test3", String.class);
50+
Assertions.assertEquals(HttpStatus.OK, response.getStatusCode());
51+
Assertions.assertEquals("OK", response.getBody());
52+
}
53+
}

0 commit comments

Comments
 (0)