Skip to content

Commit

Permalink
Add supervision controller to get results count (#29)
Browse files Browse the repository at this point in the history
Signed-off-by: Hugo Marcellin <hugo.marcelin@rte-france.com>
  • Loading branch information
Meklo authored Sep 21, 2023
1 parent 74844f1 commit 7348659
Show file tree
Hide file tree
Showing 3 changed files with 113 additions and 0 deletions.
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());
}
}
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();
}
}
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);

}
}

0 comments on commit 7348659

Please sign in to comment.