Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add supervision controller to get results count #31

Merged
merged 19 commits into from
Sep 21, 2023
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.sensitivityanalysis.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.sensitivityanalysis.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 = "/" + SensitivityAnalysisApi.API_VERSION + "/supervision")
@Tag(name = "Security analysis 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.sensitivityanalysis.server.service;

import org.gridsuite.sensitivityanalysis.server.repositories.GlobalStatusRepository;
import org.springframework.stereotype.Service;

/**
* @author Hugo Marcellin <hugo.marcelin at rte-france.com>
*/
@Service
public class SupervisionService {
private final GlobalStatusRepository globalStatusRepository;

public SupervisionService(GlobalStatusRepository globalStatusRepository) {
this.globalStatusRepository = globalStatusRepository;
}

public Integer getResultsCount() {
return (int) globalStatusRepository.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.sensitivityanalysis.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(resultCount, "0");

}
}
Loading