Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit 15895be

Browse files
committed
updated tests, added integration tests
1 parent 35aca39 commit 15895be

File tree

5 files changed

+50
-17
lines changed

5 files changed

+50
-17
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package de.filefighter.rest;
2+
3+
import de.filefighter.rest.health.rest.SystemHealthRestController;
4+
import org.junit.jupiter.api.Test;
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.test.context.SpringBootTest;
7+
8+
import static org.assertj.core.api.Assertions.assertThat;
9+
10+
@SpringBootTest
11+
class RestApplicationIntegrationTests {
12+
13+
@Autowired
14+
SystemHealthRestController controller;
15+
16+
@Test
17+
void contextLoads() {
18+
assertThat(controller).isNotNull();
19+
}
20+
}

src/test/java/de/filefighter/rest/RestApplicationTests.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

src/test/java/de/filefighter/rest/health/business/SystemHealthBusinessServiceUnitTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.time.Instant;
88

99
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
import static org.junit.jupiter.api.Assertions.assertTrue;
1011

1112
class SystemHealthBusinessServiceUnitTest {
1213

@@ -20,7 +21,7 @@ static void setUp() {
2021
@Test
2122
void getCurrentSystemHealthInfo() {
2223
SystemHealth systemHealth = systemHealthBusinessService.getCurrentSystemHealthInfo();
23-
assertEquals(0, systemHealth.getUptimeInSeconds());
24+
assertTrue(systemHealth.getUptimeInSeconds() >= 0);
2425
}
2526

2627
@Test
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package de.filefighter.rest.health.rest;
2+
3+
import org.junit.jupiter.api.Test;
4+
5+
import org.springframework.beans.factory.annotation.Autowired;
6+
import org.springframework.boot.test.context.SpringBootTest;
7+
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
8+
import org.springframework.boot.test.web.client.TestRestTemplate;
9+
import org.springframework.boot.web.server.LocalServerPort;
10+
11+
import static org.assertj.core.api.Assertions.assertThat;
12+
13+
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
14+
public class HealthRequestIntegrationTest {
15+
16+
@LocalServerPort
17+
private int port;
18+
19+
@Autowired
20+
private TestRestTemplate restTemplate;
21+
22+
@Test
23+
public void healthCheckShouldRetunUptime() throws Exception {
24+
assertThat(this.restTemplate.getForObject("http://localhost:" + port + "/health",
25+
String.class)).contains("uptimeInSeconds");
26+
}
27+
}

src/test/java/de/filefighter/rest/health/rest/HealthRestServiceUnitTest.java renamed to src/test/java/de/filefighter/rest/health/rest/SystemHealthRestServiceUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import static org.mockito.Mockito.mock;
1212
import static org.mockito.Mockito.when;
1313

14-
class HealthRestServiceUnitTest {
14+
class SystemHealthRestServiceUnitTest {
1515

1616
private static final SystemHealthBusinessService systemHealthBusinessServiceMock = mock(SystemHealthBusinessService.class);
1717
private static final SystemHealthModelAssembler systemHealthModelAssemblerMock = mock(SystemHealthModelAssembler.class);

0 commit comments

Comments
 (0)