From 7621aedb0cacd923840d45804263572a27b319c3 Mon Sep 17 00:00:00 2001 From: LE SAULNIER Kevin Date: Mon, 4 Nov 2024 15:15:49 +0100 Subject: [PATCH] fix: add not nullable in rootNetworkNodeInfoEntity + fix tests Signed-off-by: LE SAULNIER Kevin --- .../entities/RootNetworkNodeInfoEntity.java | 2 +- .../changesets/changelog_20241031T150610Z.xml | 2 ++ .../study/server/SensitivityAnalysisTest.java | 12 ++++++------ .../org/gridsuite/study/server/utils/TestUtils.java | 7 ++----- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/main/java/org/gridsuite/study/server/networkmodificationtree/entities/RootNetworkNodeInfoEntity.java b/src/main/java/org/gridsuite/study/server/networkmodificationtree/entities/RootNetworkNodeInfoEntity.java index 3ff2076e4..7863e6d12 100644 --- a/src/main/java/org/gridsuite/study/server/networkmodificationtree/entities/RootNetworkNodeInfoEntity.java +++ b/src/main/java/org/gridsuite/study/server/networkmodificationtree/entities/RootNetworkNodeInfoEntity.java @@ -43,7 +43,7 @@ public class RootNetworkNodeInfoEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "nodeInfoId", - referencedColumnName = "idNode", + referencedColumnName = "idNode", nullable = false, foreignKey = @ForeignKey(name = "rootNetworkNode_node_id_fk_constraint")) private NetworkModificationNodeInfoEntity nodeInfo; diff --git a/src/main/resources/db/changelog/changesets/changelog_20241031T150610Z.xml b/src/main/resources/db/changelog/changesets/changelog_20241031T150610Z.xml index 7fd253224..af2dd321f 100644 --- a/src/main/resources/db/changelog/changesets/changelog_20241031T150610Z.xml +++ b/src/main/resources/db/changelog/changesets/changelog_20241031T150610Z.xml @@ -32,6 +32,8 @@ validate="true"/> + diff --git a/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java b/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java index 430f3025a..ce3428890 100644 --- a/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java +++ b/src/test/java/org/gridsuite/study/server/SensitivityAnalysisTest.java @@ -605,8 +605,7 @@ void testSensitivityAnalysisParameters() throws Exception { .willReturn(WireMock.ok().withHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE).withBody(objectMapper.writeValueAsString(SENSITIVITY_ANALYSIS_PARAMETERS_UUID)))); // end mocking - StudyEntity studyEntity = insertDummyStudy(UUID.randomUUID(), UUID.randomUUID()); - UUID studyNameUserIdUuid = studyEntity.getId(); + UUID studyNameUserIdUuid = insertDummyStudy(UUID.randomUUID(), UUID.randomUUID()).getId(); assertNotNull(studyNameUserIdUuid); // Get sensitivity analysis parameters (on existing) @@ -622,8 +621,9 @@ void testSensitivityAnalysisParameters() throws Exception { wireMock.verify(WireMock.putRequestedFor(WireMock.urlPathEqualTo("/v1/parameters/" + SENSITIVITY_ANALYSIS_PARAMETERS_UUID))); // Get sensitivity analysis (not existing, so it will create default) - studyEntity.setSensitivityAnalysisParametersUuid(null); - studyRepository.save(studyEntity); + StudyEntity studyEntityToUpdate = studyRepository.findById(studyNameUserIdUuid).orElseThrow(() -> new StudyException(StudyException.Type.STUDY_NOT_FOUND)); + studyEntityToUpdate.setSensitivityAnalysisParametersUuid(null); + studyRepository.save(studyEntityToUpdate); mockMvc.perform(get("/v1/studies/{studyUuid}/sensitivity-analysis/parameters", studyNameUserIdUuid)).andExpectAll( status().isOk(), @@ -634,8 +634,8 @@ void testSensitivityAnalysisParameters() throws Exception { assertEquals(SENSITIVITY_ANALYSIS_PARAMETERS_UUID, studyRepository.findById(studyNameUserIdUuid).orElseThrow().getSensitivityAnalysisParametersUuid()); // Set sensitivity analysis parameters (will create) - studyEntity.setSensitivityAnalysisParametersUuid(null); - studyRepository.save(studyEntity); + studyEntityToUpdate.setSensitivityAnalysisParametersUuid(null); + studyRepository.save(studyEntityToUpdate); setParametersAndDoChecks(studyNameUserIdUuid, SENSITIVITY_ANALYSIS_UPDATED_PARAMETERS_JSON); diff --git a/src/test/java/org/gridsuite/study/server/utils/TestUtils.java b/src/test/java/org/gridsuite/study/server/utils/TestUtils.java index c959b78e8..6c9017b12 100644 --- a/src/test/java/org/gridsuite/study/server/utils/TestUtils.java +++ b/src/test/java/org/gridsuite/study/server/utils/TestUtils.java @@ -17,8 +17,6 @@ import org.gridsuite.study.server.networkmodificationtree.dto.BuildStatus; import org.gridsuite.study.server.networkmodificationtree.dto.NetworkModificationNode; import org.gridsuite.study.server.networkmodificationtree.dto.NodeBuildStatus; -import org.gridsuite.study.server.networkmodificationtree.entities.NodeBuildStatusEmbeddable; -import org.gridsuite.study.server.networkmodificationtree.entities.RootNetworkNodeInfoEntity; import org.gridsuite.study.server.repository.StudyEntity; import org.gridsuite.study.server.repository.rootnetwork.RootNetworkEntity; import org.gridsuite.study.server.repository.nonevacuatedenergy.NonEvacuatedEnergyParametersEntity; @@ -120,9 +118,8 @@ public static StudyEntity createDummyStudy(UUID networkUuid, String networkId, U .sensitivityAnalysisParametersUuid(sensitivityParametersUuid) .nonEvacuatedEnergyParameters(nonEvacuatedEnergyParametersEntity) .build(); - RootNetworkEntity test = RootNetworkEntity.builder().caseFormat(caseFormat).caseUuid(caseUuid).caseName(caseName).networkId(networkId).networkUuid(networkUuid).reportUuid(reportUuid).build(); - test.addRootNetworkNodeInfo(RootNetworkNodeInfoEntity.builder().nodeBuildStatus(NodeBuildStatusEmbeddable.from(BuildStatus.NOT_BUILT)).build()); - studyEntity.addRootNetwork(test); + RootNetworkEntity rootNetworkEntity = RootNetworkEntity.builder().caseFormat(caseFormat).caseUuid(caseUuid).caseName(caseName).networkId(networkId).networkUuid(networkUuid).reportUuid(reportUuid).build(); + studyEntity.addRootNetwork(rootNetworkEntity); return studyEntity; }