Skip to content

Commit

Permalink
fix: add not nullable in rootNetworkNodeInfoEntity + fix tests
Browse files Browse the repository at this point in the history
Signed-off-by: LE SAULNIER Kevin <[email protected]>
  • Loading branch information
LE SAULNIER Kevin committed Nov 4, 2024
1 parent 219d079 commit 7621aed
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
validate="true"/>
<addNotNullConstraint columnDataType="uuid" tableName="root_network_node_info" columnName="root_network_id"
validate="true"/>
<addNotNullConstraint columnDataType="uuid" tableName="root_network_node_info" columnName="node_info_id"
validate="true"/>
</changeSet>
<changeSet author="amarsli (generated)" id="1730387191936-5">
<dropForeignKeyConstraint baseTableName="root_network_node_info" constraintName="FK40i207mmx5ep57g7xnrv16t0a"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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(),
Expand All @@ -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);

Expand Down
7 changes: 2 additions & 5 deletions src/test/java/org/gridsuite/study/server/utils/TestUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}

Expand Down

0 comments on commit 7621aed

Please sign in to comment.