forked from eclipse/microprofile-config
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refs: eclipse#42 add Arquillian integration for CDI support
hacked together with @OndrejM Signed-off-by: Mark Struberg <[email protected]>
- Loading branch information
Showing
9 changed files
with
129 additions
and
17 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,23 +19,34 @@ | |
import java.util.Map; | ||
import java.util.Properties; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.eclipse.microprofile.config.Config; | ||
import org.eclipse.microprofile.config.ConfigProvider; | ||
|
||
import org.eclipse.microprofile.config.spi.ConfigSource; | ||
import org.eclipse.microprofile.config.tck.base.AbstractTest; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Mark Struberg</a> | ||
*/ | ||
public class ConfigProviderTest { | ||
|
||
public class ConfigProviderTest extends AbstractTest { | ||
|
||
private @Inject Config config; | ||
|
||
@Deployment | ||
public static JavaArchive deploy() { | ||
return allIn("configProviderTest.jar").addClass(ConfigProviderTest.class); | ||
} | ||
|
||
@Test | ||
public void testEnvironmentConfigSource() { | ||
Map<String, String> env = System.getenv(); | ||
Config config = ConfigProvider.getConfig(); | ||
for (Map.Entry<String, String> envEntry : env.entrySet()) { | ||
Assert.assertEquals(envEntry.getValue(), config.getString(envEntry.getKey()).get()); | ||
} | ||
|
@@ -44,7 +55,6 @@ public void testEnvironmentConfigSource() { | |
@Test | ||
public void testPropertyConfigSource() { | ||
Properties properties = System.getProperties(); | ||
Config config = ConfigProvider.getConfig(); | ||
|
||
for (Map.Entry<Object, Object> propEntry : properties.entrySet()) { | ||
Assert.assertEquals(propEntry.getValue(), config.getString((String) propEntry.getKey()).orElse("")); | ||
|
@@ -53,7 +63,6 @@ public void testPropertyConfigSource() { | |
|
||
@Test | ||
public void testDynamicValueInPropertyConfigSource() { | ||
Config config = ConfigProvider.getConfig(); | ||
String configKey = "tck.config.test.systemproperty.dynamic.value"; | ||
String configValue = "myDynamicValue;"; | ||
|
||
|
@@ -63,25 +72,21 @@ public void testDynamicValueInPropertyConfigSource() { | |
|
||
@Test | ||
public void testJavaConfigPropertyFilesConfigSource() { | ||
Config config = ConfigProvider.getConfig(); | ||
Assert.assertEquals(config.getString("tck.config.test.javaconfig.properties.key1").get(), "VALue1"); | ||
} | ||
|
||
@Test | ||
public void testNonExistingConfigKey() { | ||
Config config = ConfigProvider.getConfig(); | ||
Assert.assertFalse(config.getString("tck.config.test.keydoesnotexist").isPresent()); | ||
} | ||
|
||
@Test | ||
public void testEmptyConfigTreatedAsNotExisting() { | ||
Config config = ConfigProvider.getConfig(); | ||
Assert.assertFalse(config.getString("tck.config.test.javaconfig.emptyvalue").isPresent()); | ||
} | ||
|
||
@Test | ||
public void testGetConfigSources() { | ||
Config config = ConfigProvider.getConfig(); | ||
Iterable<ConfigSource> configSources = config.getConfigSources(); | ||
Assert.assertNotNull(configSources); | ||
|
||
|
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 |
---|---|---|
|
@@ -16,27 +16,37 @@ | |
*/ | ||
package org.eclipse.microprofile.config.tck; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.eclipse.microprofile.config.Config; | ||
import org.eclipse.microprofile.config.ConfigProvider; | ||
import org.eclipse.microprofile.config.tck.base.AbstractTest; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Mark Struberg</a> | ||
*/ | ||
public class ConverterTest { | ||
public class ConverterTest extends AbstractTest { | ||
|
||
private @Inject Config config; | ||
|
||
@Deployment | ||
public static JavaArchive deploy() { | ||
return allIn("converterTest.jar").addClass(ConverterTest.class); | ||
} | ||
|
||
|
||
@Test | ||
public void testIntegerConverter() { | ||
Config config = ConfigProvider.getConfig(); | ||
Integer value = config.getValue("tck.config.test.javaconfig.converter.integervalue", Integer.class).get(); | ||
Assert.assertEquals(value, Integer.valueOf(1234)); | ||
|
||
} | ||
|
||
@Test | ||
public void testFloatConverter() { | ||
Config config = ConfigProvider.getConfig(); | ||
Float value = config.getValue("tck.config.test.javaconfig.converter.floatvalue", Float.class).get(); | ||
Assert.assertEquals(value, Float.valueOf(12.34f)); | ||
|
||
|
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 |
---|---|---|
|
@@ -16,20 +16,30 @@ | |
*/ | ||
package org.eclipse.microprofile.config.tck; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.eclipse.microprofile.config.Config; | ||
import org.eclipse.microprofile.config.ConfigProvider; | ||
import org.eclipse.microprofile.config.tck.base.AbstractTest; | ||
import org.jboss.arquillian.container.test.api.Deployment; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Mark Struberg</a> | ||
*/ | ||
public class CustomConfigSourceTest { | ||
public class CustomConfigSourceTest extends AbstractTest { | ||
|
||
private @Inject Config config; | ||
|
||
@Deployment | ||
public static JavaArchive deploy() { | ||
return allIn("customConfigSourceTest.jar").addClass(CustomConfigSourceTest.class); | ||
} | ||
|
||
|
||
@Test | ||
public void testConfigSourceProvider() { | ||
Config config = ConfigProvider.getConfig(); | ||
|
||
Assert.assertEquals(config.getString("tck.config.test.customDbConfig.key1").get(), "valueFromDb1"); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
tck/src/main/java/org/eclipse/microprofile/config/tck/base/AbstractTest.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,42 @@ | ||
/* | ||
* Copyright (c) 2016-2017 Mark Struberg and others | ||
* | ||
* 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.base; | ||
|
||
import org.eclipse.microprofile.config.tck.configsources.CustomDbConfigSource; | ||
import org.eclipse.microprofile.config.tck.converters.DuckConverter; | ||
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; | ||
|
||
|
||
/** | ||
* @author <a href="mailto:[email protected]">Mark Struberg</a> | ||
*/ | ||
public class AbstractTest extends Arquillian { | ||
|
||
protected static JavaArchive allIn(String testName) { | ||
JavaArchive testJar = ShrinkWrap | ||
.create(JavaArchive.class, testName) | ||
.addPackage(CustomDbConfigSource.class.getPackage()) | ||
.addPackage(DuckConverter.class.getPackage()) | ||
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml"); | ||
|
||
return testJar; | ||
} | ||
|
||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.