|  | 
|  | 1 | +/* | 
|  | 2 | + * Copyright (c) 2017, 2021 Contributors to the Eclipse Foundation | 
|  | 3 | + * | 
|  | 4 | + * See the NOTICE file(s) distributed with this work for additional | 
|  | 5 | + * information regarding copyright ownership. | 
|  | 6 | + * | 
|  | 7 | + * Licensed under the Apache License, Version 2.0 (the "License"); | 
|  | 8 | + * You may not use this file except in compliance with the License. | 
|  | 9 | + * You may obtain a copy of the License at | 
|  | 10 | + * | 
|  | 11 | + *     http://www.apache.org/licenses/LICENSE-2.0 | 
|  | 12 | + * | 
|  | 13 | + * Unless required by applicable law or agreed to in writing, software | 
|  | 14 | + * distributed under the License is distributed on an "AS IS" BASIS, | 
|  | 15 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
|  | 16 | + * See the License for the specific language governing permissions and | 
|  | 17 | + * limitations under the License. | 
|  | 18 | + */ | 
|  | 19 | + | 
|  | 20 | +package org.eclipse.microprofile.config.tck; | 
|  | 21 | + | 
|  | 22 | +import jakarta.inject.Inject; | 
|  | 23 | +import org.eclipse.microprofile.config.Config; | 
|  | 24 | +import org.eclipse.microprofile.config.spi.Converter; | 
|  | 25 | +import org.eclipse.microprofile.config.tck.MapConverterBean.EnumKey; | 
|  | 26 | +import org.eclipse.microprofile.config.tck.MapConverterBean.EnumValue; | 
|  | 27 | +import org.eclipse.microprofile.config.tck.converters.Pizza; | 
|  | 28 | +import org.eclipse.microprofile.config.tck.converters.PizzaConverter; | 
|  | 29 | +import org.eclipse.microprofile.config.tck.util.AdditionalAssertions; | 
|  | 30 | +import org.jboss.arquillian.container.test.api.Deployment; | 
|  | 31 | +import org.jboss.arquillian.testng.Arquillian; | 
|  | 32 | +import org.jboss.shrinkwrap.api.ShrinkWrap; | 
|  | 33 | +import org.jboss.shrinkwrap.api.asset.EmptyAsset; | 
|  | 34 | +import org.jboss.shrinkwrap.api.spec.JavaArchive; | 
|  | 35 | +import org.jboss.shrinkwrap.api.spec.WebArchive; | 
|  | 36 | +import org.testng.Assert; | 
|  | 37 | +import org.testng.annotations.Test; | 
|  | 38 | + | 
|  | 39 | +import java.net.MalformedURLException; | 
|  | 40 | +import java.net.URI; | 
|  | 41 | +import java.net.URISyntaxException; | 
|  | 42 | +import java.net.URL; | 
|  | 43 | +import java.time.Duration; | 
|  | 44 | +import java.time.Instant; | 
|  | 45 | +import java.time.LocalDate; | 
|  | 46 | +import java.time.LocalDateTime; | 
|  | 47 | +import java.time.LocalTime; | 
|  | 48 | +import java.time.OffsetDateTime; | 
|  | 49 | +import java.time.OffsetTime; | 
|  | 50 | +import java.util.Arrays; | 
|  | 51 | +import java.util.Collections; | 
|  | 52 | +import java.util.LinkedHashSet; | 
|  | 53 | +import java.util.List; | 
|  | 54 | +import java.util.Optional; | 
|  | 55 | +import java.util.Set; | 
|  | 56 | + | 
|  | 57 | +import static org.eclipse.microprofile.config.tck.base.AbstractTest.addFile; | 
|  | 58 | +import static org.eclipse.microprofile.config.tck.util.AdditionalAssertions.assertURLArrayEquals; | 
|  | 59 | +import static org.eclipse.microprofile.config.tck.util.AdditionalAssertions.assertURLListEquals; | 
|  | 60 | +import static org.eclipse.microprofile.config.tck.util.AdditionalAssertions.assertURLSetEquals; | 
|  | 61 | + | 
|  | 62 | +/** | 
|  | 63 | + * Test the implicit converter handling. | 
|  | 64 | + **/ | 
|  | 65 | +public class MapConverterTest extends Arquillian { | 
|  | 66 | + | 
|  | 67 | +    @Deployment | 
|  | 68 | +    public static WebArchive deploy() { | 
|  | 69 | +        JavaArchive testJar = ShrinkWrap | 
|  | 70 | +            .create(JavaArchive.class, "mapConverterTest.jar") | 
|  | 71 | +            .addPackage(PizzaConverter.class.getPackage()) | 
|  | 72 | +            .addClasses(MapConverterTest.class, MapConverterBean.class, AdditionalAssertions.class) | 
|  | 73 | +            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml") | 
|  | 74 | +            .addAsServiceProvider(Converter.class, PizzaConverter.class) | 
|  | 75 | +            .as(JavaArchive.class); | 
|  | 76 | +        addFile(testJar, "META-INF/microprofile-config.properties"); | 
|  | 77 | +        WebArchive war = ShrinkWrap | 
|  | 78 | +            .create(WebArchive.class, "mapConverterTest.war") | 
|  | 79 | +            .addAsLibrary(testJar); | 
|  | 80 | +        return war; | 
|  | 81 | +    } | 
|  | 82 | + | 
|  | 83 | +    @Inject | 
|  | 84 | +    private MapConverterBean converterBean; | 
|  | 85 | + | 
|  | 86 | +    /////////////////////////////////// Test Map////////////////////////// | 
|  | 87 | + | 
|  | 88 | + | 
|  | 89 | +    @Test | 
|  | 90 | +    public void testStringStringMapInjection() { | 
|  | 91 | +        Assert.assertEquals(converterBean.getMyStringStringMap().size(), 2); | 
|  | 92 | +        Assert.assertEquals(converterBean.getMyStringStringMap().get("key1"), "string.string.value1"); | 
|  | 93 | +        Assert.assertEquals(converterBean.getMyStringStringMap().get("key2"), "string.string.value2"); | 
|  | 94 | +    } | 
|  | 95 | + | 
|  | 96 | +    @Test | 
|  | 97 | +    public void testStringIntegerMapInjection() { | 
|  | 98 | +        Assert.assertEquals(converterBean.getMyStringIntegerMap().size(), 2); | 
|  | 99 | +        Assert.assertEquals(converterBean.getMyStringIntegerMap().get("key1"), Integer.valueOf(100)); | 
|  | 100 | +        Assert.assertEquals(converterBean.getMyStringIntegerMap().get("key2"), Integer.valueOf(200)); | 
|  | 101 | +    } | 
|  | 102 | + | 
|  | 103 | +    @Test | 
|  | 104 | +    public void testIntegerStringMapInjection() { | 
|  | 105 | +        Assert.assertEquals(converterBean.getMyIntegerStringMap().size(), 2); | 
|  | 106 | +        Assert.assertEquals(converterBean.getMyIntegerStringMap().get(100), "integer.string.value1"); | 
|  | 107 | +        Assert.assertEquals(converterBean.getMyIntegerStringMap().get(200), "integer.string.value2"); | 
|  | 108 | +    } | 
|  | 109 | + | 
|  | 110 | +    @Test | 
|  | 111 | +    public void testEnumEnumMapInjection() { | 
|  | 112 | +        Assert.assertEquals(converterBean.getMyEnumEnumMap().size(), 2); | 
|  | 113 | +        Assert.assertEquals(converterBean.getMyEnumEnumMap().get(EnumKey.key1), EnumValue.enum1); | 
|  | 114 | +        Assert.assertEquals(converterBean.getMyEnumEnumMap().get(EnumKey.key2), EnumValue.enum2); | 
|  | 115 | +    } | 
|  | 116 | +} | 
0 commit comments