/
ImplicitConverterTest.java
128 lines (108 loc) · 4.95 KB
/
ImplicitConverterTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/*
* Copyright (c) 2016-2017 Contributors to the Eclipse Foundation
*
* See the NOTICE file(s) distributed with this work for additional
* information regarding copyright ownership.
*
* 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 org.eclipse.microprofile.config.tck;
import static org.eclipse.microprofile.config.tck.base.AbstractTest.addFile;
import java.time.YearMonth;
import javax.enterprise.context.Dependent;
import javax.inject.Inject;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.eclipse.microprofile.config.tck.converters.implicit.ConvTestTypeWCharSequenceParse;
import org.eclipse.microprofile.config.tck.converters.implicit.ConvTestTypeWStringCt;
import org.eclipse.microprofile.config.tck.converters.implicit.ConvTestTypeWStringValueOf;
import org.eclipse.microprofile.config.tck.converters.implicit.SomeEnumToConvert;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.testng.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.testng.Assert;
import org.testng.annotations.Test;
/**
* Test the implicit converter handling.
*
* @author <a href="mailto:struberg@yahoo.de">Mark Struberg</a>
* @author <a href="mailto:jmesnil@redhat.com">Jeff Mesnil</a>
* @author <a href="mailto:emijiang@uk.ibm.com">Emily Jiang</a>
*
*/
public class ImplicitConverterTest extends Arquillian {
@Deployment
public static WebArchive deploy() {
JavaArchive testJar = ShrinkWrap
.create(JavaArchive.class, "implicitConverterTest.jar")
.addPackage(ConvTestTypeWStringCt.class.getPackage())
.addClasses(ParseConverterInjection.class, ImplicitConverterTest.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
.as(JavaArchive.class);
addFile(testJar, "META-INF/microprofile-config.properties");
WebArchive war = ShrinkWrap
.create(WebArchive.class, "implicitConverterTest.war")
.addAsLibrary(testJar);
return war;
}
private @Inject Config config;
private @Inject ParseConverterInjection parserConverterInjection;
@Test
public void testImplicitConverterStringCt() {
ConvTestTypeWStringCt value = config.getValue("tck.config.test.javaconfig.converter.implicit.stringCt",
ConvTestTypeWStringCt.class);
Assert.assertNotNull(value);
Assert.assertEquals(value.getVal(), "stringCt");
}
@Test
public void testImplicitConverterStringValueOf() {
ConvTestTypeWStringValueOf value = config.getValue("tck.config.test.javaconfig.converter.implicit.stringValueOf",
ConvTestTypeWStringValueOf.class);
Assert.assertNotNull(value);
Assert.assertEquals(value.getVal(), "stringValueOf");
}
@Test
public void testImplicitConverterCharSequenceParse() {
ConvTestTypeWCharSequenceParse value = config.getValue("tck.config.test.javaconfig.converter.implicit.charSequenceParse",
ConvTestTypeWCharSequenceParse.class);
Assert.assertNotNull(value);
Assert.assertEquals(value.getVal(), "charSequenceParse");
}
@Test
public void testImplicitConverterCharSequenceParseJavaTime() {
YearMonth value = config.getValue("tck.config.test.javaconfig.converter.implicit.charSequenceParse.yearmonth",
YearMonth.class);
Assert.assertNotNull(value);
Assert.assertEquals(value, YearMonth.parse("2017-12"));
}
@Test
public void testImplicitConverterCharSequenceParseJavaTimeInjection() {
Assert.assertNotNull(parserConverterInjection.yearMonth);
Assert.assertEquals(parserConverterInjection.yearMonth, YearMonth.parse("2017-12"));
}
@Test
public void testImplicitConverterEnumValueOf() {
SomeEnumToConvert value = config.getValue("tck.config.test.javaconfig.converter.implicit.enumValueOf",
SomeEnumToConvert.class);
Assert.assertNotNull(value);
Assert.assertEquals(value, SomeEnumToConvert.BAZ);
Assert.assertEquals(value.name(), "BAZ");
}
@Dependent
public static class ParseConverterInjection {
private @Inject @ConfigProperty(name = "tck.config.test.javaconfig.converter.implicit.charSequenceParse.yearmonth") YearMonth yearMonth;
}
}