Skip to content

Commit

Permalink
Add test for EnumConverter (#1075)
Browse files Browse the repository at this point in the history
  • Loading branch information
radcortez authored Jan 2, 2024
1 parent 7cff829 commit b038a80
Showing 1 changed file with 27 additions and 13 deletions.
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"));
}
}

0 comments on commit b038a80

Please sign in to comment.