-
Notifications
You must be signed in to change notification settings - Fork 115
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add additional spec support in rest Java (#10118)
* add support for contract spec tests * add support for entity stake spec tests * add support for history entities * various bug fixes --------- Signed-off-by: Jesse Nelson <[email protected]>
- Loading branch information
Showing
22 changed files
with
399 additions
and
138 deletions.
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
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
41 changes: 41 additions & 0 deletions
41
...r-rest-java/src/main/java/com/hedera/mirror/restjava/converter/StringToLongConverter.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,41 @@ | ||
/* | ||
* Copyright (C) 2025 Hedera Hashgraph, LLC | ||
* | ||
* Licensed 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 com.hedera.mirror.restjava.converter; | ||
|
||
import com.hedera.mirror.common.domain.entity.EntityId; | ||
import jakarta.inject.Named; | ||
import org.springframework.boot.context.properties.ConfigurationPropertiesBinding; | ||
import org.springframework.core.convert.converter.Converter; | ||
import org.springframework.util.StringUtils; | ||
|
||
@Named | ||
@ConfigurationPropertiesBinding | ||
public class StringToLongConverter implements Converter<String, Long> { | ||
@Override | ||
public Long convert(String source) { | ||
if (!StringUtils.hasText(source)) { | ||
return null; | ||
} | ||
|
||
|
||
var parts = source.split("\\."); | ||
if (parts.length == 3) { | ||
return EntityId.of(source).getId(); | ||
} | ||
return Long.parseLong(source); | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...st-java/src/test/java/com/hedera/mirror/restjava/converter/StringToLongConverterTest.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,54 @@ | ||
/* | ||
* Copyright (C) 2025 Hedera Hashgraph, LLC | ||
* | ||
* Licensed 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 com.hedera.mirror.restjava.converter; | ||
|
||
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
|
||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.junit.jupiter.params.provider.NullAndEmptySource; | ||
import org.junit.jupiter.params.provider.ValueSource; | ||
|
||
class StringToLongConverterTest { | ||
|
||
@ParameterizedTest(name = "Convert \"{0}\" to Long") | ||
@CsvSource(delimiter = ',', textBlock = """ | ||
1, 1 | ||
0, 0 | ||
0.0.2, 2 | ||
""") | ||
void testConverter(String source, Long expected) { | ||
var converter = new StringToLongConverter(); | ||
Long actual = converter.convert(source); | ||
assertThat(actual).isEqualTo(expected); | ||
} | ||
|
||
@ParameterizedTest(name = "Convert \"{0}\" to Long") | ||
@NullAndEmptySource | ||
void testInvalidSource(String source) { | ||
var converter = new StringToLongConverter(); | ||
assertThat(converter.convert(source)).isNull(); | ||
} | ||
|
||
@ParameterizedTest(name = "Fail to convert \"{0}\" to Long") | ||
@ValueSource(strings = {"bad", "1.557", "5444.0"}) | ||
void testConverterFailures(String source) { | ||
var converter = new StringToLongConverter(); | ||
assertThrows(NumberFormatException.class, () -> converter.convert(source)); | ||
} | ||
} |
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
Oops, something went wrong.