Skip to content
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

Add test for EnumConverter #1075

Merged
merged 1 commit into from
Jan 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.net.URL;
import java.time.LocalDate;

import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.spi.Converter;
import org.junit.jupiter.api.Test;

Expand All @@ -23,8 +22,9 @@
class ImplicitConverterTest {
@Test
void implicitURLConverter() {
Config config = buildConfig(
"my.url", "https://github.com/smallrye/smallrye-config/");
SmallRyeConfig config = new SmallRyeConfigBuilder()
.withSources(KeyValuesConfigSource.config("my.url", "https://github.com/smallrye/smallrye-config/"))
.build();
URL url = config.getValue("my.url", URL.class);
assertNotNull(url);
assertEquals("https", url.getProtocol());
Expand All @@ -34,8 +34,9 @@ void implicitURLConverter() {

@Test
void implicitLocalDateConverter() {
Config config = buildConfig(
"my.date", "2019-04-01");
SmallRyeConfig config = new SmallRyeConfigBuilder()
.withSources(KeyValuesConfigSource.config("my.date", "2019-04-01"))
.build();
LocalDate date = config.getValue("my.date", LocalDate.class);
assertNotNull(date);
assertEquals(2019, date.getYear());
Expand Down Expand Up @@ -105,7 +106,7 @@ public void convertMyOtherEnum() {
}

@Test
public void testIllegalEnumConfigUtilConversion() {
public void illegalEnumConfigUtilConversion() {
HyphenateEnumConverter<MyEnum> hyphenateEnumConverter = new HyphenateEnumConverter<>(MyEnum.class);
IllegalArgumentException exception = assertThrows(IllegalArgumentException.class,
() -> hyphenateEnumConverter.convert("READUNCOMMITTED"));
Expand All @@ -115,13 +116,6 @@ public void testIllegalEnumConfigUtilConversion() {
exception.getMessage());
}

private static Config buildConfig(String... keyValues) {
return new SmallRyeConfigBuilder()
.addDefaultSources()
.withSources(KeyValuesConfigSource.config(keyValues))
.build();
}

public enum KeyEncryptionAlgorithm {
RSA_OAEP,
RSA_OAEP_256,
Expand Down Expand Up @@ -183,4 +177,24 @@ void convertKeyEncryptionAlgorithm() {
assertEquals(KeyEncryptionAlgorithm.PBES2_HS512_A256KW, converter.convert("PBES2-HS512-A256KW"));
assertEquals(KeyEncryptionAlgorithm.PBES2_HS512_A256KW, converter.convert("pbes2-hs512-a256kw"));
}

enum HTTPConduit {
QuarkusCXFDefault,
CXFDefault,
HttpClientHTTPConduitFactory,
URLConnectionHTTPConduitFactory
}

@Test
void convertHttpConduit() {
HyphenateEnumConverter<HTTPConduit> converter = new HyphenateEnumConverter<>(HTTPConduit.class);
assertEquals(HTTPConduit.QuarkusCXFDefault, converter.convert("QuarkusCXFDefault"));
assertEquals(HTTPConduit.QuarkusCXFDefault, converter.convert("quarkus-cxf-default"));
assertEquals(HTTPConduit.CXFDefault, converter.convert("CXFDefault"));
assertEquals(HTTPConduit.CXFDefault, converter.convert("cxf-default"));
assertEquals(HTTPConduit.HttpClientHTTPConduitFactory, converter.convert("HttpClientHTTPConduitFactory"));
assertEquals(HTTPConduit.HttpClientHTTPConduitFactory, converter.convert("http-client-http-conduit-factory"));
assertEquals(HTTPConduit.URLConnectionHTTPConduitFactory, converter.convert("URLConnectionHTTPConduitFactory"));
assertEquals(HTTPConduit.URLConnectionHTTPConduitFactory, converter.convert("url-connection-http-conduit-factory"));
}
}
Loading