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

Commit 3a05ea9

Browse files
committed
broken commit
1 parent 10b0827 commit 3a05ea9

File tree

9 files changed

+162
-7
lines changed

9 files changed

+162
-7
lines changed

.run/RestApplication.run.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="RestApplication" type="SpringBootApplicationConfigurationType" factoryName="Spring Boot">
3+
<module name="RestApi" />
4+
<option name="SPRING_BOOT_MAIN_CLASS" value="de.filefighter.rest.RestApplication" />
5+
<option name="ALTERNATIVE_JRE_PATH" />
6+
<method v="2">
7+
<option name="Make" enabled="true" />
8+
</method>
9+
</configuration>
10+
</component>

.run/TESTS.run.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<component name="ProjectRunConfigurationManager">
2+
<configuration default="false" name="TESTS" type="MavenRunConfiguration" factoryName="Maven">
3+
<MavenSettings>
4+
<option name="myGeneralSettings" />
5+
<option name="myRunnerSettings" />
6+
<option name="myRunnerParameters">
7+
<MavenRunnerParameters>
8+
<option name="profiles">
9+
<set />
10+
</option>
11+
<option name="goals">
12+
<list>
13+
<option value="clean" />
14+
<option value="test" />
15+
</list>
16+
</option>
17+
<option name="pomFileName" value="pom.xml" />
18+
<option name="profilesMap">
19+
<map />
20+
</option>
21+
<option name="resolveToWorkspace" value="false" />
22+
<option name="workingDirPath" value="$PROJECT_DIR$" />
23+
</MavenRunnerParameters>
24+
</option>
25+
</MavenSettings>
26+
<method v="2" />
27+
</configuration>
28+
</component>

src/main/java/de/filefighter/rest/config/SwaggerConfiguration.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ private ApiInfo apiInfo() {
3030
"REST-API of the FileFighter application.",
3131
"0.1",
3232
"terms of service url",
33-
new Contact("FileFighter Dev-Team", "https://github.com/filefighter/", "comming soon"),
33+
new Contact("FileFighter Dev-Team", "https://github.com/filefighter/", "[email protected]"),
3434
"MIT License",
3535
"https://github.com/filefighter/restapi/blob/master/LICENSE",
3636
Collections.emptyList()

src/main/java/de/filefighter/rest/health/business/SystemHealthBusinessService.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,20 @@
88
@Service
99
public class SystemHealthBusinessService {
1010

11-
private final long serverStartedAt = Instant.now().getEpochSecond();
11+
private final long serverStartedAt;
12+
13+
public SystemHealthBusinessService() {
14+
this.serverStartedAt = this.getCurrentEpochSeconds();
15+
}
1216

1317
public SystemHealth getCurrentSystemHealthInfo(){
14-
long currentEpoch = Instant.now().getEpochSecond();
18+
long currentEpoch = getCurrentEpochSeconds();
1519
return SystemHealth.builder()
1620
.uptimeInSeconds(currentEpoch - serverStartedAt)
1721
.create();
1822
}
23+
24+
public long getCurrentEpochSeconds(){
25+
return Instant.now().getEpochSecond();
26+
}
1927
}

src/main/java/de/filefighter/rest/rest/RestErrorController.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@
1010
@RestController
1111
public class RestErrorController implements ErrorController {
1212

13-
private static final String DEFAULT_PATH = "/error";
13+
public static final String DEFAULT_ERROR_PATH = "/error";
1414

15-
@RequestMapping(value = DEFAULT_PATH)
15+
@RequestMapping(value = DEFAULT_ERROR_PATH)
1616
public EntityModel<ServerResponse> error() {
1717
return new ServerResponse("denied", "This endpoint does not exist.").toModel();
1818
}
1919

2020
@Override
2121
public String getErrorPath() {
22-
return DEFAULT_PATH;
22+
return DEFAULT_ERROR_PATH;
2323
}
2424
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
package de.filefighter.rest;
1+
/*package de.filefighter.rest;
22
3+
import org.junit.Ignore;
34
import org.junit.jupiter.api.Test;
45
import org.springframework.boot.test.context.SpringBootTest;
56
@@ -11,3 +12,4 @@ void contextLoads() {
1112
}
1213
1314
}
15+
*/
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package de.filefighter.rest.health.business;
2+
3+
import de.filefighter.rest.health.data.SystemHealth;
4+
import org.junit.Before;
5+
import org.junit.jupiter.api.BeforeAll;
6+
import org.junit.jupiter.api.Test;
7+
8+
import java.time.Instant;
9+
10+
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
12+
class SystemHealthBusinessServiceUnitTest {
13+
14+
private SystemHealthBusinessService systemHealthBusinessService;
15+
16+
@Before
17+
public void setUp(){
18+
systemHealthBusinessService = new SystemHealthBusinessService();
19+
}
20+
21+
@Test
22+
void getCurrentSystemHealthInfo() {
23+
SystemHealth systemHealth = systemHealthBusinessService.getCurrentSystemHealthInfo();
24+
assertEquals(0, systemHealth.getUptimeInSeconds());
25+
}
26+
27+
@Test
28+
void getCurrentEpochSecondsReturnsEpochSeconds() {
29+
long expectedSeconds = Instant.now().getEpochSecond();
30+
long epochSeconds = systemHealthBusinessService.getCurrentEpochSeconds();
31+
assertEquals(expectedSeconds, epochSeconds);
32+
}
33+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package de.filefighter.rest.health.business;
2+
3+
import de.filefighter.rest.health.data.SystemHealth;
4+
import org.junit.Before;
5+
import org.junit.jupiter.api.BeforeAll;
6+
import org.junit.jupiter.api.Test;
7+
import org.springframework.hateoas.EntityModel;
8+
9+
import static org.junit.jupiter.api.Assertions.*;
10+
11+
class SystemHealthModelAssemblerUnitTest {
12+
13+
private SystemHealthModelAssembler systemHealthModelAssembler;
14+
15+
@Before
16+
public void setUp(){
17+
systemHealthModelAssembler = new SystemHealthModelAssembler();
18+
}
19+
20+
@Test
21+
void toModel() {
22+
SystemHealth systemHealth = SystemHealth.builder().uptimeInSeconds(420).create();
23+
EntityModel<SystemHealth> systemHealthEntityModel = systemHealthModelAssembler.toModel(systemHealth);
24+
25+
assertEquals(systemHealth, systemHealthEntityModel.getContent());
26+
assertTrue(systemHealthEntityModel.getLink("self").isPresent());
27+
assertTrue(systemHealthEntityModel.getLink("ugabuga").isEmpty());
28+
}
29+
}
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package de.filefighter.rest.rest;
2+
3+
import org.junit.Before;
4+
import org.junit.jupiter.api.BeforeEach;
5+
import org.junit.jupiter.api.Test;
6+
import org.springframework.test.web.servlet.MockMvc;
7+
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
8+
9+
import static org.hamcrest.Matchers.is;
10+
import static org.springframework.test.web.client.match.MockRestRequestMatchers.jsonPath;
11+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
12+
13+
14+
import static org.junit.jupiter.api.Assertions.assertEquals;
15+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
16+
17+
class RestErrorControllerUnitTest {
18+
19+
private MockMvc mockMvc;
20+
private RestErrorController restErrorController;
21+
22+
@BeforeEach
23+
void setUp() {
24+
25+
}
26+
27+
restErrorController = new RestErrorController();
28+
mockMvc = MockMvcBuilders.standaloneSetup(restErrorController).build();
29+
}
30+
31+
@Test
32+
void errorHandleingDoesWork() throws Exception {
33+
mockMvc.perform(get(RestErrorController.DEFAULT_ERROR_PATH))
34+
.andExpect(status().isOk())
35+
.andReturn();
36+
}
37+
38+
@Test
39+
void getErrorPath() {
40+
String expectedPath = RestErrorController.DEFAULT_ERROR_PATH;
41+
String actualPath = restErrorController.getErrorPath();
42+
43+
assertEquals(expectedPath, actualPath);
44+
}
45+
}

0 commit comments

Comments
 (0)