-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add supervision controller to get results count (#29)
Signed-off-by: Hugo Marcellin <hugo.marcelin@rte-france.com>
- Loading branch information
Showing
3 changed files
with
113 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
src/main/java/org/gridsuite/shortcircuit/server/SupervisionController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Copyright (c) 2023, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package org.gridsuite.shortcircuit.server; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponse; | ||
import io.swagger.v3.oas.annotations.responses.ApiResponses; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import org.gridsuite.shortcircuit.server.service.SupervisionService; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
/** | ||
* @author Hugo Marcellin <hugo.marcelin at rte-france.com> | ||
*/ | ||
@RestController | ||
@RequestMapping(value = "/" + ShortCircuitApi.API_VERSION + "/supervision") | ||
@Tag(name = "Short circuit server - Supervision") | ||
public class SupervisionController { | ||
private final SupervisionService supervisionService; | ||
|
||
public SupervisionController(SupervisionService supervisionService) { | ||
this.supervisionService = supervisionService; | ||
} | ||
|
||
@GetMapping(value = "/results-count") | ||
@Operation(summary = "Get results count") | ||
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The count of all results")}) | ||
public ResponseEntity<Integer> getResultsCount() { | ||
return ResponseEntity.ok().contentType(MediaType.APPLICATION_JSON).body(supervisionService.getResultsCount()); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/org/gridsuite/shortcircuit/server/service/SupervisionService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** | ||
* Copyright (c) 2023, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package org.gridsuite.shortcircuit.server.service; | ||
|
||
import org.gridsuite.shortcircuit.server.repositories.ResultRepository; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* @author Hugo Marcellin <hugo.marcelin at rte-france.com> | ||
*/ | ||
@Service | ||
public class SupervisionService { | ||
private final ResultRepository resultRepository; | ||
|
||
public SupervisionService(ResultRepository resultRepository) { | ||
this.resultRepository = resultRepository; | ||
} | ||
|
||
public Integer getResultsCount() { | ||
return (int) resultRepository.count(); | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
src/test/java/org/gridsuite/shortcircuit/server/SupervisionControllerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* Copyright (c) 2023, RTE (http://www.rte-france.com) | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
*/ | ||
package org.gridsuite.shortcircuit.server; | ||
|
||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import org.springframework.test.web.servlet.MvcResult; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
/** | ||
* @author Hugo Marcellin <hugo.marcelin at rte-france.com> | ||
*/ | ||
@RunWith(SpringRunner.class) | ||
@AutoConfigureMockMvc | ||
@SpringBootTest | ||
public class SupervisionControllerTest { | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@Test | ||
public void testResultCount() throws Exception { | ||
//get the result timeline uuid of the calculation | ||
MvcResult mvcResult = mockMvc.perform(get("/v1/supervision/results-count")) | ||
.andExpect(status().isOk()) | ||
.andExpect(content().contentType(MediaType.APPLICATION_JSON)) | ||
.andReturn(); | ||
|
||
String resultCount = mvcResult.getResponse().getContentAsString(); | ||
assertEquals("0", resultCount); | ||
|
||
} | ||
} |