-
Notifications
You must be signed in to change notification settings - Fork 2
Fix import parameters #990
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
Open
etiennehomer
wants to merge
14
commits into
main
Choose a base branch
from
fix_import_parameters
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3014f4f
Fix import parameters
etiennehomer d1a1b24
Merge branch 'main' into fix_import_parameters
etiennehomer 91d863f
clean
etiennehomer b067516
fix tests
etiennehomer 5256bd4
Merge branch 'main' into fix_import_parameters
etiennehomer 6ad4a55
sonar fixes
etiennehomer 98899c5
clean import
etiennehomer 2e1acd4
move to JsonUtils
etiennehomer 23ba8a2
test with objects
etiennehomer 3ad708d
thow on serialization
etiennehomer fbad7e8
use common objectMapper
etiennehomer 16795fc
fix hibernate session problem in test
etiennehomer fa9ca1f
Add JsonUtilsTest
etiennehomer 4bbadcc
Merge branch 'main' into fix_import_parameters
etiennehomer File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
src/main/resources/db/changelog/changesets/changelog_20260519T112945Z.xml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| <?xml version="1.1" encoding="UTF-8" standalone="no"?> | ||
| <databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog" | ||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
| xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-latest.xsd"> | ||
| <changeSet author="homereti" id="1747612800000-1"> | ||
| <update tableName="import_parameters"> | ||
| <column name="import_parameters" value="NULL"/> | ||
| <where>import_parameters=''</where> | ||
| </update> | ||
| </changeSet> | ||
| </databaseChangeLog> |
88 changes: 88 additions & 0 deletions
88
src/test/java/org/gridsuite/study/server/JsonUtilsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| /** | ||
| * Copyright (c) 2026, 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.study.server; | ||
|
|
||
| import org.gridsuite.study.server.error.StudyBusinessErrorCode; | ||
| import org.gridsuite.study.server.error.StudyException; | ||
| import org.gridsuite.study.server.utils.JsonUtils; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.*; | ||
|
|
||
| /** | ||
| * @author Etienne HOMER <etiennehomer@gmail.com> | ||
| */ | ||
| class JsonUtilsTest { | ||
|
|
||
| @Test | ||
| void shouldSerializeImportParameters() { | ||
| Map<String, Object> params = new HashMap<>(); | ||
| params.put("string", "value"); | ||
| params.put("int", 123); | ||
| params.put("bool", true); | ||
| params.put("list", List.of("a", "b")); | ||
| params.put("map", Map.of("k", "v")); | ||
| params.put("null", null); | ||
|
|
||
| Map<String, String> result = JsonUtils.serializeImportParameters(params); | ||
|
|
||
| assertEquals("\"value\"", result.get("string")); | ||
| assertEquals("123", result.get("int")); | ||
| assertEquals("true", result.get("bool")); | ||
| assertEquals("[\"a\",\"b\"]", result.get("list")); | ||
| assertEquals("{\"k\":\"v\"}", result.get("map")); | ||
| assertEquals("null", result.get("null")); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldReturnEmptyMapWhenSerializeNull() { | ||
| Map<String, String> result = JsonUtils.serializeImportParameters(null); | ||
| assertNotNull(result); | ||
| assertTrue(result.isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldDeserializeImportParameters() { | ||
| Map<String, String> rawParams = new HashMap<>(); | ||
| rawParams.put("string", "\"value\""); | ||
| rawParams.put("int", "123"); | ||
| rawParams.put("bool", "true"); | ||
| rawParams.put("list", "[\"a\",\"b\"]"); | ||
| rawParams.put("map", "{\"k\":\"v\"}"); | ||
| rawParams.put("null", "null"); | ||
| rawParams.put("realNull", null); | ||
|
|
||
| Map<String, Object> result = JsonUtils.deserializeImportParameters(rawParams); | ||
|
|
||
| assertEquals("value", result.get("string")); | ||
| assertEquals(123, result.get("int")); | ||
| assertEquals(true, result.get("bool")); | ||
| assertEquals(List.of("a", "b"), result.get("list")); | ||
| assertEquals(Map.of("k", "v"), result.get("map")); | ||
| assertNull(result.get("null")); | ||
| assertNull(result.get("realNull")); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldReturnEmptyMapWhenDeserializeNull() { | ||
| Map<String, Object> result = JsonUtils.deserializeImportParameters(null); | ||
| assertNotNull(result); | ||
| assertTrue(result.isEmpty()); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldThrowExceptionWhenDeserializeInvalidJson() { | ||
| Map<String, String> rawParams = Map.of("invalid", "{notJson}"); | ||
| StudyException exception = assertThrows(StudyException.class, () -> JsonUtils.deserializeImportParameters(rawParams)); | ||
| assertEquals(StudyBusinessErrorCode.UNPROCESSABLE_IMPORT_PARAMETER, exception.getBusinessErrorCode()); | ||
| assertTrue(exception.getMessage().contains("Import parameter 'invalid => {notJson}' is not valid JSON")); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.