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

Migrate various endpoints to add rootNetworkUuid in path #655

Open
wants to merge 6 commits into
base: root-network-networkmap-endpoints
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 39 additions & 28 deletions src/main/java/org/gridsuite/study/server/StudyController.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2372,7 +2372,6 @@ public String evaluateFilter(UUID nodeUuid, UUID rootNetworkUuid, boolean inUpst

public String exportFilter(UUID rootNetworkUuid, UUID filterUuid) {
// will use root node network of the study
//TODO: buggy, what networkUuid to choose ?
return filterService.exportFilter(rootNetworkService.getNetworkUuid(rootNetworkUuid), filterUuid);
}

Expand Down
24 changes: 16 additions & 8 deletions src/test/java/org/gridsuite/study/server/FilterServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import org.gridsuite.study.server.repository.StudyRepository;
import org.gridsuite.study.server.service.FilterService;
import org.gridsuite.study.server.service.NetworkModificationTreeService;
import org.gridsuite.study.server.utils.StudyTestUtils;
import org.gridsuite.study.server.utils.TestUtils;
import org.gridsuite.study.server.utils.WireMockUtils;
import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch;
Expand Down Expand Up @@ -74,6 +75,9 @@ class FilterServiceTest {
@Autowired
private ObjectMapper objectMapper;

@Autowired
private StudyTestUtils studyTestUtils;

@BeforeEach
void setup() {
wireMockServer = new WireMockServer(wireMockConfig().dynamicPort());
Expand Down Expand Up @@ -117,6 +121,7 @@ private RootNode getRootNode(UUID study) throws Exception {
void testEvaluateFilter() throws Exception {
StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID);
UUID studyNameUserIdUuid = studyEntity.getId();
UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid);
UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId();

// whatever string is allowed but given here a json string for more expressive
Expand Down Expand Up @@ -148,8 +153,8 @@ void testEvaluateFilter() throws Exception {

UUID stubUuid = wireMockUtils.stubFilterEvaluate(NETWORK_UUID_STRING, responseBody);

MvcResult mvcResult = mockMvc.perform(post("/v1/studies/{studyUuid}/nodes/{nodeUuid}/filters/evaluate",
studyNameUserIdUuid, rootNodeUuid)
MvcResult mvcResult = mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/filters/evaluate",
studyNameUserIdUuid, firstRootNetworkUuid, rootNodeUuid)
.content(sendBody).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andReturn();
Expand All @@ -165,6 +170,7 @@ void testEvaluateFilterNotFoundError() throws Exception {

StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID);
UUID studyNameUserIdUuid = studyEntity.getId();
UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid);
UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId();

// whatever string is allowed but given here a json string for more expressive
Expand All @@ -187,8 +193,8 @@ void testEvaluateFilterNotFoundError() throws Exception {
}
""";

mockMvc.perform(post("/v1/studies/{studyUuid}/nodes/{nodeUuid}/filters/evaluate",
studyNameUserIdUuid, rootNodeUuid)
mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/filters/evaluate",
studyNameUserIdUuid, firstRootNetworkUuid, rootNodeUuid)
.content(sendBody).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is5xxServerError())
.andReturn();
Expand All @@ -202,6 +208,7 @@ void testEvaluateFilterError() throws Exception {

StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID);
UUID studyNameUserIdUuid = studyEntity.getId();
UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyNameUserIdUuid);
UUID rootNodeUuid = getRootNode(studyNameUserIdUuid).getId();

// whatever string is allowed but given here a json string for more expressive
Expand All @@ -224,8 +231,8 @@ void testEvaluateFilterError() throws Exception {
}
""";

mockMvc.perform(post("/v1/studies/{studyUuid}/nodes/{nodeUuid}/filters/evaluate",
studyNameUserIdUuid, rootNodeUuid)
mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/filters/evaluate",
studyNameUserIdUuid, firstRootNetworkUuid, rootNodeUuid)
.content(sendBody).contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is5xxServerError())
.andReturn();
Expand All @@ -238,6 +245,7 @@ void testExportFilter() throws Exception {

StudyEntity studyEntity = insertDummyStudy(UUID.fromString(NETWORK_UUID_STRING), CASE_UUID);
UUID studyUuid = studyEntity.getId();
UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid);
String responseBody = """
[
{"id":"MANDA7COND.41","type":"SHUNT_COMPENSATOR","distributionKey":null},
Expand All @@ -246,8 +254,8 @@ void testExportFilter() throws Exception {
""";
UUID stubUuid = wireMockUtils.stubFilterExport(NETWORK_UUID_STRING, FILTER_UUID_STRING, responseBody);

MvcResult mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/filters/{filterId}/elements",
studyUuid, FILTER_UUID_STRING))
MvcResult mvcResult = mockMvc.perform(get("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/filters/{filterId}/elements",
studyUuid, firstRootNetworkUuid, FILTER_UUID_STRING))
.andExpect(status().isOk())
.andReturn();
String resultAsString = mvcResult.getResponse().getContentAsString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -423,7 +423,7 @@ void testBuildQuotaExceeded() throws Exception {
testBuildWithNodeUuid(studyNameUserIdUuid, modificationNode1.getId(), rootNetworkUuid, userId, userProfileQuotaExceededStubId);

// build modificationNode2: cannot be done cause quota is 1 build max (err 403)
MvcResult result = mockMvc.perform(post("/v1/studies/{studyUuid}/nodes/{nodeUuid}/build", studyNameUserIdUuid, modificationNode2.getId())
MvcResult result = mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/build", studyNameUserIdUuid, rootNetworkUuid, modificationNode2.getId())
.header("userId", userId)
.contentType(APPLICATION_JSON)
).andExpect(status().isForbidden())
Expand Down Expand Up @@ -2545,7 +2545,7 @@ void testUpdateOfBuildStatus() throws Exception {

private void testBuildWithNodeUuid(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, String userId, UUID profileStubId) throws Exception {
// build node
mockMvc.perform(post("/v1/studies/{studyUuid}/nodes/{nodeUuid}/build", studyUuid, nodeUuid)
mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/build", studyUuid, rootNetworkUuid, nodeUuid)
.header(USER_ID_HEADER, userId))
.andExpect(status().isOk());

Expand Down Expand Up @@ -2573,7 +2573,7 @@ private void testBuildWithNodeUuid(UUID studyUuid, UUID nodeUuid, UUID rootNetwo

private void testBuildAndStopWithNodeUuid(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid, String userId, UUID profileStubId) throws Exception {
// build node
mockMvc.perform(post("/v1/studies/{studyUuid}/nodes/{nodeUuid}/build", studyUuid, nodeUuid)
mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/build", studyUuid, rootNetworkUuid, nodeUuid)
.header(USER_ID_HEADER, userId))
.andExpect(status().isOk());

Expand All @@ -2600,7 +2600,7 @@ private void testBuildAndStopWithNodeUuid(UUID studyUuid, UUID nodeUuid, UUID ro
networkModificationTreeService.updateNodeBuildStatus(nodeUuid, rootNetworkUuid, NodeBuildStatus.from(BuildStatus.BUILDING));

// stop build
mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/build/stop", studyUuid, nodeUuid))
mockMvc.perform(put("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/build/stop", studyUuid, rootNetworkUuid, nodeUuid))
.andExpect(status().isOk());

buildStatusMessage = output.receive(TIMEOUT, STUDY_UPDATE_DESTINATION);
Expand All @@ -2620,7 +2620,7 @@ private void testBuildAndStopWithNodeUuid(UUID studyUuid, UUID nodeUuid, UUID ro
// builds on network 2 will fail
private void testBuildFailedWithNodeUuid(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid) throws Exception {
// build node
mockMvc.perform(post("/v1/studies/{studyUuid}/nodes/{nodeUuid}/build", studyUuid, nodeUuid)
mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/build", studyUuid, rootNetworkUuid, nodeUuid)
.header(USER_ID_HEADER, USER_ID))
.andExpect(status().isOk());

Expand Down Expand Up @@ -2650,7 +2650,7 @@ private void testBuildFailedWithNodeUuid(UUID studyUuid, UUID nodeUuid, UUID roo
// builds on network 3 will throw an error on networkmodificationservice call
private void testBuildErrorWithNodeUuid(UUID studyUuid, UUID nodeUuid, UUID rootNetworkUuid) throws Exception {
// build node
mockMvc.perform(post("/v1/studies/{studyUuid}/nodes/{nodeUuid}/build", studyUuid, nodeUuid)
mockMvc.perform(post("/v1/studies/{studyUuid}/root-networks/{rootNetworkUuid}/nodes/{nodeUuid}/build", studyUuid, rootNetworkUuid, nodeUuid)
.header(USER_ID_HEADER, USER_ID))
.andExpect(status().isInternalServerError());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import org.gridsuite.study.server.repository.rootnetwork.RootNetworkRepository;
import org.gridsuite.study.server.repository.voltageinit.StudyVoltageInitParametersEntity;
import org.gridsuite.study.server.service.NetworkService;
import org.gridsuite.study.server.utils.StudyTestUtils;
import org.gridsuite.study.server.utils.elasticsearch.DisableElasticsearch;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -95,6 +96,8 @@ class NetworkModificationUnitTest {
private RootNetworkNodeInfoRepository rootNetworkNodeInfoRepository;
@Autowired
private RootNetworkRepository rootNetworkRepository;
@Autowired
private StudyTestUtils studyTestUtils;

@BeforeEach
void setup() {
Expand Down Expand Up @@ -143,8 +146,9 @@ void unbuildNode() {
assertEquals(BuildStatus.BUILT, rootNetworkNodeInfoEntity1.getNodeBuildStatus().getLocalBuildStatus());
assertEquals(BuildStatus.BUILT, rootNetworkNodeInfoEntity2.getNodeBuildStatus().getLocalBuildStatus());
assertEquals(BuildStatus.NOT_BUILT, rootNetworkNodeInfoEntity3.getNodeBuildStatus().getLocalBuildStatus());
UUID firstRootNetworkUuid = studyTestUtils.getStudyFirstRootNetworkUuid(studyUuid);

studyController.unbuildNode(studyUuid, node1Uuid);
studyController.unbuildNode(studyUuid, firstRootNetworkUuid, node1Uuid);

/* rootNode
* |
Expand Down
Loading
Loading