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

Refactor constant USER_ID #584

Open
wants to merge 3 commits into
base: main
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
4 changes: 0 additions & 4 deletions src/main/java/org/gridsuite/study/server/StudyConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,6 @@ private StudyConstants() {
public static final String QUERY_PARAM_REPORT_UUID = "reportUuid";
public static final String QUERY_PARAM_REPORTER_ID = "reporterId";
public static final String QUERY_PARAM_REPORT_TYPE = "reportType";
public static final String HEADER_RECEIVER = "receiver";
public static final String HEADER_BUS_ID = "busId";
public static final String HEADER_IMPORT_PARAMETERS = "importParameters";
public static final String HEADER_MESSAGE = "message";
public static final String HEADER_USER_ID = "userId";
public static final String QUERY_PARAM_ONLY_STASHED = "onlyStashed";
public static final String QUERY_PARAM_STASHED = "stashed";
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/gridsuite/study/server/StudyController.java
Original file line number Diff line number Diff line change
Expand Up @@ -890,7 +890,7 @@ public ResponseEntity<Void> setLoadflowProvider(@PathVariable("studyUuid") UUID
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The security analysis provider is set")})
public ResponseEntity<Void> setSecurityAnalysisProvider(@PathVariable("studyUuid") UUID studyUuid,
@RequestBody(required = false) String provider,
@RequestHeader("userId") String userId) {
@RequestHeader(HEADER_USER_ID) String userId) {
studyService.updateSecurityAnalysisProvider(studyUuid, provider, userId);
return ResponseEntity.ok().build();
}
Expand Down Expand Up @@ -1838,7 +1838,7 @@ public ResponseEntity<Void> setNonEvacuatedEnergyParametersInfos(
@ApiResponses(value = {@ApiResponse(responseCode = "200", description = "The sensitivity analysis non evacuated energy provider is set")})
public ResponseEntity<Void> setNonEvacuatedEnergyProvider(@PathVariable("studyUuid") UUID studyUuid,
@RequestBody(required = false) String provider,
@RequestHeader("userId") String userId) {
@RequestHeader(HEADER_USER_ID) String userId) {
studyService.updateNonEvacuatedEnergyProvider(studyUuid, provider, userId);
return ResponseEntity.ok().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ public class NotificationService {
public static final String HEADER_PARENT_NODE = "parentNode";
public static final String HEADER_REMOVE_CHILDREN = "removeChildren";
public static final String HEADER_INDEXATION_STATUS = "indexation_status";
public static final String HEADER_RECEIVER = "receiver";
public static final String HEADER_MESSAGE = "message";
public static final String HEADER_IMPORT_PARAMETERS = "importParameters";
public static final String HEADER_BUS_ID = "busId";

public static final String QUERY_PARAM_RECEIVER = "receiver";

public static final String NODE_UPDATED = "nodeUpdated";
public static final String NODE_DELETED = "nodeDeleted";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import java.util.concurrent.TimeUnit;
import java.util.function.Consumer;

import static org.gridsuite.study.server.StudyConstants.*;
import static org.gridsuite.study.server.notification.NotificationService.*;
import static org.gridsuite.study.server.dto.ComputationType.*;

/**
Expand Down
31 changes: 15 additions & 16 deletions src/test/java/org/gridsuite/study/server/LoadFlowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@
import java.io.IOException;
import java.util.*;

import static org.gridsuite.study.server.StudyConstants.HEADER_RECEIVER;
import static org.gridsuite.study.server.notification.NotificationService.HEADER_RECEIVER;
import static org.gridsuite.study.server.StudyConstants.HEADER_USER_ID;
import static org.gridsuite.study.server.dto.ComputationType.LOAD_FLOW;
import static org.gridsuite.study.server.notification.NotificationService.HEADER_UPDATE_TYPE;
import static org.junit.Assert.*;
Expand Down Expand Up @@ -126,8 +127,6 @@ public class LoadFlowTest {

private static final long TIMEOUT = 1000;

private static final String USER_ID_HEADER = "userId";

private static final String DEFAULT_PROVIDER = "defaultProvider";
private static final String OTHER_PROVIDER = "otherProvider";

Expand Down Expand Up @@ -373,12 +372,12 @@ public void testLoadFlow() throws Exception {

// run a loadflow on root node (not allowed)
mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/loadflow/run", studyNameUserIdUuid, rootNodeUuid)
.header("userId", "userId"))
.header(HEADER_USER_ID, "userId"))
.andExpect(status().isForbidden());

//run a loadflow
mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/loadflow/run", studyNameUserIdUuid, modificationNode3Uuid)
.header("userId", "userId"))
.header(HEADER_USER_ID, "userId"))
.andExpect(status().isOk());

checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_LOADFLOW_STATUS);
Expand Down Expand Up @@ -413,7 +412,7 @@ public void testLoadFlow() throws Exception {

// loadflow failed
mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/loadflow/run", studyNameUserIdUuid, modificationNode2Uuid)
.header("userId", "userId"))
.header(HEADER_USER_ID, "userId"))
.andExpect(status().isOk());

checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_LOADFLOW_FAILED);
Expand All @@ -434,7 +433,7 @@ public void testGetLimitViolations() throws Exception {

//run a loadflow
mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/loadflow/run?limitReduction=0.7", studyNameUserIdUuid, modificationNode1Uuid)
.header("userId", "userId"))
.header(HEADER_USER_ID, "userId"))
.andExpect(status().isOk())
.andReturn();

Expand Down Expand Up @@ -486,7 +485,7 @@ public void testInvalidateStatus() throws Exception {

//run a loadflow
mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/loadflow/run?limitReduction=0.7", studyNameUserIdUuid, modificationNode1Uuid)
.header("userId", "userId"))
.header(HEADER_USER_ID, "userId"))
.andExpect(status().isOk())
.andReturn();

Expand All @@ -497,7 +496,7 @@ public void testInvalidateStatus() throws Exception {

// invalidate status
mockMvc.perform(put("/v1/studies/{studyUuid}/loadflow/invalidate-status", studyNameUserIdUuid)
.header("userId", "userId")).andExpect(status().isOk());
.header(HEADER_USER_ID, "userId")).andExpect(status().isOk());
checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_LOADFLOW_STATUS);
assertTrue(TestUtils.getRequestsDone(1, server).stream().anyMatch(r -> r.matches("/v1/results/invalidate-status\\?resultUuid=" + LOADFLOW_RESULT_UUID)));
}
Expand All @@ -522,7 +521,7 @@ public void testDeleteLoadFlowResults() throws Exception {

//run a loadflow
mockMvc.perform(put("/v1/studies/{studyUuid}/nodes/{nodeUuid}/loadflow/run", studyNameUserIdUuid, modificationNode3Uuid)
.header("userId", "userId"))
.header(HEADER_USER_ID, "userId"))
.andExpect(status().isOk());

checkUpdateModelStatusMessagesReceived(studyNameUserIdUuid, NotificationService.UPDATE_TYPE_LOADFLOW_STATUS);
Expand Down Expand Up @@ -627,7 +626,7 @@ public void testNoResult() throws Exception {
private void createOrUpdateParametersAndDoChecks(UUID studyNameUserIdUuid, String parameters, String userId, HttpStatusCode status) throws Exception {
mockMvc.perform(
post("/v1/studies/{studyUuid}/loadflow/parameters", studyNameUserIdUuid)
.header("userId", userId)
.header(HEADER_USER_ID, userId)
.contentType(MediaType.ALL)
.content(parameters))
.andExpect(status().is(status.value()));
Expand Down Expand Up @@ -709,7 +708,7 @@ public void testResetLoadFlowParametersUserHasValidParamsInProfileButNoExistingL
// the following testGetDefaultProviders tests are related to StudyTest::testGetDefaultProviders but with a user and different profile cases
@Test
public void testGetDefaultProvidersFromProfile() throws Exception {
mockMvc.perform(get("/v1/loadflow-default-provider").header(USER_ID_HEADER, VALID_PARAMS_IN_PROFILE_USER_ID)).andExpectAll(
mockMvc.perform(get("/v1/loadflow-default-provider").header(HEADER_USER_ID, VALID_PARAMS_IN_PROFILE_USER_ID)).andExpectAll(
status().isOk(),
content().string(OTHER_PROVIDER));
var requests = TestUtils.getRequestsDone(2, server);
Expand All @@ -719,7 +718,7 @@ public void testGetDefaultProvidersFromProfile() throws Exception {

@Test
public void testGetDefaultProvidersFromProfileInvalid() throws Exception {
mockMvc.perform(get("/v1/loadflow-default-provider").header(USER_ID_HEADER, INVALID_PARAMS_IN_PROFILE_USER_ID)).andExpectAll(
mockMvc.perform(get("/v1/loadflow-default-provider").header(HEADER_USER_ID, INVALID_PARAMS_IN_PROFILE_USER_ID)).andExpectAll(
status().isOk(),
content().string(DEFAULT_PROVIDER));
var requests = TestUtils.getRequestsDone(3, server);
Expand All @@ -730,7 +729,7 @@ public void testGetDefaultProvidersFromProfileInvalid() throws Exception {

@Test
public void testGetDefaultProvidersWithoutProfile() throws Exception {
mockMvc.perform(get("/v1/loadflow-default-provider").header(USER_ID_HEADER, NO_PROFILE_USER_ID)).andExpectAll(
mockMvc.perform(get("/v1/loadflow-default-provider").header(HEADER_USER_ID, NO_PROFILE_USER_ID)).andExpectAll(
status().isOk(),
content().string(DEFAULT_PROVIDER));
var requests = TestUtils.getRequestsDone(2, server);
Expand All @@ -740,7 +739,7 @@ public void testGetDefaultProvidersWithoutProfile() throws Exception {

@Test
public void testGetDefaultProvidersWithoutParamInProfile() throws Exception {
mockMvc.perform(get("/v1/loadflow-default-provider").header(USER_ID_HEADER, NO_PARAMS_IN_PROFILE_USER_ID)).andExpectAll(
mockMvc.perform(get("/v1/loadflow-default-provider").header(HEADER_USER_ID, NO_PARAMS_IN_PROFILE_USER_ID)).andExpectAll(
status().isOk(),
content().string(DEFAULT_PROVIDER));
var requests = TestUtils.getRequestsDone(2, server);
Expand Down Expand Up @@ -826,7 +825,7 @@ private NetworkModificationNode createNetworkModificationNode(UUID studyUuid, UU
jsonObject.put("modificationGroupUuid", modificationGroupUuid);
mnBodyJson = jsonObject.toString();

mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header("userId", "userId"))
mockMvc.perform(post("/v1/studies/{studyUuid}/tree/nodes/{id}", studyUuid, parentNodeUuid).content(mnBodyJson).contentType(MediaType.APPLICATION_JSON).header(HEADER_USER_ID, "userId"))
.andExpect(status().isOk());
var mess = output.receive(TIMEOUT, studyUpdateDestination);
assertNotNull(mess);
Expand Down
Loading
Loading