Skip to content

Commit

Permalink
refs: eclipse#42 add Arquillian integration for CDI support
Browse files Browse the repository at this point in the history
hacked together with @OndrejM

Signed-off-by: Mark Struberg <[email protected]>
  • Loading branch information
struberg committed Mar 10, 2017
1 parent 8ac2220 commit c390f91
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 17 deletions.
45 changes: 45 additions & 0 deletions tck/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,22 @@
<artifactId>microprofile-config-tck</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<arquillian.version>1.1.7.Final</arquillian.version>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.jboss.arquillian</groupId>
<artifactId>arquillian-bom</artifactId>
<version>${arquillian.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>


<dependencies>
<dependency>
Expand All @@ -21,12 +37,41 @@
<version>1.0-SNAPSHOT</version>
</dependency>

<dependency>
<!-- actually only referenced in JavaDoc -->
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-annotation_1.2_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-jcdi_1.1_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.geronimo.specs</groupId>
<artifactId>geronimo-atinject_1.0_spec</artifactId>
<version>1.0</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.9</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.testng</groupId>
<artifactId>arquillian-testng-container</artifactId>
<version>${arquillian.version}</version>
</dependency>


</dependencies>

</project>
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand All @@ -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(""));
Expand All @@ -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;";

Expand All @@ -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);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
}
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.

0 comments on commit c390f91

Please sign in to comment.