-
Notifications
You must be signed in to change notification settings - Fork 212
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
Fix: Duplicate keys in JSON produced for Catalog objects #915 #955
Merged
Merged
Changes from 20 commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
a582379
Using JsonTypeInfo.As.EXISTING_PROPERTY, making discriminator use sam…
vedansh-5 0d2b89f
created template file typeInfoAnnotation in server-templates, linked …
vedansh-5 49bcf5a
Added 6 tests
vedansh-5 b2bd13b
added 3 more tests
vedansh-5 f26edfd
All tests added
vedansh-5 3736684
Added readme file
vedansh-5 dd3d108
Formatted the code
vedansh-5 b9128ad
Assert exact JSON string, got rid of append calls, added comments bef…
vedansh-5 ac7463a
Added rountTrip method and using it in testcases
vedansh-5 55ca322
applied spotlessApply
vedansh-5 f0d4259
removed vscode settings, using string literals in tests
vedansh-5 f13a5a4
ran spotlessApply
vedansh-5 e767e2d
let's do assertThat(deserialized).isEqualTo(original)
vedansh-5 47ef32f
Parameterized Tests
vedansh-5 301badd
fine tuning
vedansh-5 16ad417
leaner build and test file
vedansh-5 c985f0a
recursiveComparing in catalog
vedansh-5 e202f6e
spotlessApply
vedansh-5 d08cc72
Delete .vscode directory
vedansh-5 623773b
Update .gitignore
vedansh-5 4e37832
type-field serialized once
vedansh-5 c1d3f03
Merge pull request #10 from vedansh-5/master
vedansh-5 644820c
inline verifyRoundTrip
vedansh-5 9c44b8a
added test jsonformat
vedansh-5 8374c50
Merge pull request #11 from vedansh-5/master
vedansh-5 8df8e28
formatting
vedansh-5 89ca9b5
Merge pull request #12 from vedansh-5/master
vedansh-5 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 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
125 changes: 125 additions & 0 deletions
125
...ent-model/src/test/java/org/apache/polaris/core/admin/model/CatalogSerializationTest.java
This file contains 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,125 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
package org.apache.polaris.core.admin.model; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import com.fasterxml.jackson.core.JsonProcessingException; | ||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import java.util.stream.Stream; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.Arguments; | ||
import org.junit.jupiter.params.provider.MethodSource; | ||
|
||
public class CatalogSerializationTest { | ||
|
||
private ObjectMapper mapper; | ||
private static final String TEST_LOCATION = "s3://test/"; | ||
private static final String TEST_CATALOG_NAME = "test-catalog"; | ||
private static final String TEST_ROLE_ARN = "arn:aws:iam::123456789012:role/test-role"; | ||
|
||
@BeforeEach | ||
public void setUp() { | ||
mapper = new ObjectMapper(); | ||
} | ||
|
||
/** | ||
* Helper method to verify round-trip serialization/deserialization of Catalog objects. Ensures | ||
* all fields are preserved correctly through the process. | ||
* | ||
* @param original The catalog object to test | ||
* @return The deserialized catalog for additional assertions if needed | ||
*/ | ||
private Catalog verifyRoundTrip(Catalog original) throws JsonProcessingException { | ||
String json = mapper.writeValueAsString(original); | ||
Catalog deserialized = mapper.readValue(json, Catalog.class); | ||
assertThat(deserialized).usingRecursiveComparison().isEqualTo(original); | ||
return deserialized; | ||
} | ||
|
||
@ParameterizedTest(name = "{0}") | ||
@MethodSource("catalogTestCases") | ||
public void testCatalogSerialization(String description, Catalog catalog) | ||
throws JsonProcessingException { | ||
verifyRoundTrip(catalog); | ||
vedansh-5 marked this conversation as resolved.
Show resolved
Hide resolved
vedansh-5 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
private static Stream<Arguments> catalogTestCases() { | ||
Stream<Arguments> basicCases = | ||
Stream.of( | ||
Arguments.of( | ||
"Basic catalog", | ||
new Catalog( | ||
Catalog.TypeEnum.INTERNAL, | ||
TEST_CATALOG_NAME, | ||
new CatalogProperties(TEST_LOCATION), | ||
new AwsStorageConfigInfo(TEST_ROLE_ARN, StorageConfigInfo.StorageTypeEnum.S3))), | ||
Arguments.of("Null fields", new Catalog(Catalog.TypeEnum.INTERNAL, null, null, null)), | ||
Arguments.of( | ||
"Long name", | ||
new Catalog( | ||
Catalog.TypeEnum.INTERNAL, | ||
"a".repeat(1000), | ||
new CatalogProperties(TEST_LOCATION), | ||
null)), | ||
Arguments.of( | ||
"Unicode characters", | ||
new Catalog( | ||
Catalog.TypeEnum.INTERNAL, "测试目录", new CatalogProperties(TEST_LOCATION), null)), | ||
Arguments.of( | ||
"Empty strings", | ||
new Catalog( | ||
Catalog.TypeEnum.INTERNAL, | ||
"", | ||
new CatalogProperties(""), | ||
new AwsStorageConfigInfo("", StorageConfigInfo.StorageTypeEnum.S3))), | ||
Arguments.of( | ||
"Special characters", | ||
new Catalog( | ||
Catalog.TypeEnum.INTERNAL, | ||
"test\"catalog", | ||
new CatalogProperties(TEST_LOCATION), | ||
new AwsStorageConfigInfo(TEST_ROLE_ARN, StorageConfigInfo.StorageTypeEnum.S3))), | ||
Arguments.of( | ||
"Whitespace", | ||
new Catalog( | ||
Catalog.TypeEnum.INTERNAL, | ||
" test catalog ", | ||
new CatalogProperties(" " + TEST_LOCATION + " "), | ||
null))); | ||
|
||
Stream<Arguments> arnCases = | ||
Stream.of( | ||
"arn:aws:iam::123456789012:role/test-role", | ||
"arn:aws:iam::123456789012:role/service-role/test-role", | ||
"arn:aws:iam::123456789012:role/path/to/role") | ||
.map( | ||
arn -> | ||
Arguments.of( | ||
"ARN: " + arn, | ||
new Catalog( | ||
Catalog.TypeEnum.INTERNAL, | ||
TEST_CATALOG_NAME, | ||
new CatalogProperties(TEST_LOCATION), | ||
new AwsStorageConfigInfo(arn, StorageConfigInfo.StorageTypeEnum.S3)))); | ||
|
||
return Stream.concat(basicCases, arnCases); | ||
} | ||
} |
This file contains 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,29 @@ | ||
{{! | ||
Licensed to the Apache Software Foundation (ASF) under one | ||
or more contributor license agreements. See the NOTICE file | ||
distributed with this work for additional information | ||
regarding copyright ownership. The ASF licenses this file | ||
to you under the Apache License, Version 2.0 (the | ||
"License"); you may not use this file except in compliance | ||
with the License. You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, | ||
software distributed under the License is distributed on an | ||
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
KIND, either express or implied. See the License for the | ||
specific language governing permissions and limitations | ||
under the License. | ||
}} | ||
@JsonTypeInfo( | ||
use = JsonTypeInfo.Id.NAME, | ||
include = JsonTypeInfo.As.EXISTING_PROPERTY, | ||
property = "{{propertyName}}", | ||
visible = true | ||
) | ||
@JsonSubTypes({ | ||
{{#mappedModels}} | ||
@JsonSubTypes.Type(value = {{modelName}}.class, name = "{{mappingName}}"){{^-last}},{{/-last}} | ||
{{/mappedModels}} | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. new line |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not simply assertThat(deserialized).isEqualTo(original)?
Do you think the
.equals()
method inCatalog
does not take nested objects into account?