Skip to content

Commit

Permalink
refs: eclipse#384 backport tck for ConfigAccessor and fix TCK setup
Browse files Browse the repository at this point in the history
This also includes a fix to avoid OS specific hacks
(envconfig.* properties)
  • Loading branch information
struberg committed Oct 4, 2018
1 parent 442525f commit a6717b5
Show file tree
Hide file tree
Showing 6 changed files with 397 additions and 101 deletions.
16 changes: 8 additions & 8 deletions tck/running_the_tck.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ To enable the tests in your project you need to add the following dependency to
Some tests are asserting statements related to environment variables.
The following environment variable and their values must be present in the test runner environment:

* `my_int_property` with the value `45`
* `MY_BOOLEAN_PROPERTY` with the value `true`
* `my_string_property` with the value `haha`
* `MY_STRING_PROPERTY` with the value `woohoo`
* `envconfig_my_int_property` with the value `45`
* `ENVCONFIG_MY_BOOLEAN_PROPERTY` with the value `true`
* `envconfig_my_string_property` with the value `haha`
* `ENVCONFIG_MY_STRING_PROPERTY` with the value `woohoo`

See below for an example configuration to provide these environment variables in a Maven pom.xml.

Expand Down Expand Up @@ -97,10 +97,10 @@ If you use Apache Maven then the tests are run via the `maven-surefire-plugin`
</suiteXmlFiles>
<!-- These env variables are required for org.eclipse.configjsr.CDIPropertyNameMatchingTest -->
<environmentVariables>
<my_int_property>45</my_int_property>
<MY_BOOLEAN_PROPERTY>true</MY_BOOLEAN_PROPERTY>
<my_string_property>haha</my_string_property>
<MY_STRING_PROPERTY>woohoo</MY_STRING_PROPERTY>
<envconfig_my_int_property>45</envconfig_my_int_property>
<ENVCONFIG_MY_BOOLEAN_PROPERTY>true</ENVCONFIG_MY_BOOLEAN_PROPERTY>
<envconfig_my_string_property>haha</envconfig_my_string_property>
<ENVCONFIG_MY_STRING_PROPERTY>woohoo</ENVCONFIG_MY_STRING_PROPERTY>
</environmentVariables>
</configuration>
</plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,21 @@

package org.eclipse.microprofile.config.tck;

import static org.hamcrest.Matchers.anyOf;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.is;

import javax.enterprise.context.Dependent;
import javax.inject.Inject;
import javax.enterprise.inject.spi.CDI;
import org.eclipse.microprofile.config.Config;

import org.eclipse.microprofile.config.inject.ConfigProperty;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.testng.Arquillian;
import org.jboss.shrinkwrap.api.Archive;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
Expand All @@ -51,13 +53,16 @@
*/
public class CDIPropertyNameMatchingTest extends Arquillian {

private @Inject Config config;

@Deployment
public static Archive deployment() {
JavaArchive testJar = ShrinkWrap
.create(JavaArchive.class, "CDIPropertyNameMatchingTest.jar")
.addClasses(CDIPropertyNameMatchingTest.class, SimpleValuesBean.class)
.addAsManifestResource(new StringAsset(
"envconfig.my.int/property=3"+
"\nenvconfig.my.string/property=fake"),
"javaconfig.properties")
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
.as(JavaArchive.class);

Expand All @@ -71,30 +76,17 @@ public static Archive deployment() {
public void checkSetup() {
//check whether the environment variables were populated by the executor correctly

if (!"45".equals(System.getenv("my_int_property"))) {
Assert.fail("Before running this test, the environment variable \"my_int_property\" must be set with the value of 45");
if (!"45".equals(System.getenv("envconfig_my_int_property"))) {
Assert.fail("Before running this test, the environment variable \"envconfig_my_int_property\" must be set with the value of 45");
}
if (!"true".equals(System.getenv("MY_BOOLEAN_PROPERTY"))) {
Assert.fail("Before running this test, the environment variable \"MY_BOOLEAN_Property\" must be set with the value of true");
if (!"true".equals(System.getenv("ENVCONFIG_MY_BOOLEAN_PROPERTY"))) {
Assert.fail("Before running this test, the environment variable \"ENVCONFIG_MY_BOOLEAN_PROPERTY\" must be set with the value of true");
}

// Environment variables are case insensitive on Windows platforms
if(System.getProperty("os.name").contains("Windows")) {
String myStringProp = System.getenv("MY_STRING_PROPERTY");
if (!"woohoo".equals(myStringProp) && !"haha".equals(myStringProp)) {
Assert.fail("Before running this test on a Windows platform, " +
"the environment variable \"MY_STRING_PROPERTY\" must be set with the value of woohoo or haha");
}
if (!"haha".equals(System.getenv("envconfig_my_string_property"))) {
Assert.fail("Before running this test, the environment variable \"envconfig_my_string_property\" must be set with the value of haha");
}
else { // Not operating on Windows platform
if (!"haha".equals(System.getenv("my_string_property"))) {
Assert.fail("Before running this test on a non-Windows platform, " +
"the environment variable \"my_string_property\" must be set with the value of haha");
}
if (!"woohoo".equals(System.getenv("MY_STRING_PROPERTY"))) {
Assert.fail("Before running this test on a non-Windows platform, " +
"the environment variable \"MY_STRING_PROPERTY\" must be set with the value of woohoo");
}
if (!"woohoo".equals(System.getenv("ENVCONFIG_MY_STRING_PROPERTY"))) {
Assert.fail("Before running this test, the environment variable \"ENVCONFIG_MY_STRING_PROPERTY\" must be set with the value of woohoo");
}

}
Expand All @@ -103,22 +95,30 @@ public void checkSetup() {
public void testPropertyFromEnvironmentVariables() {
SimpleValuesBean bean = getBeanOfType(SimpleValuesBean.class);

// Environment variables are case insensitive on Windows platforms, use Config to
// retrieve the "os.name" System property.
if(config.getValue("os.name", String.class).contains("Windows")) {
assertThat(bean.getStringProperty(), anyOf(equalTo("haha"),equalTo("woohoo")) );
}
else { // non-Windows
assertThat(bean.getStringProperty(), is(equalTo("haha")));
}

assertThat(bean.getBooleanProperty(), is(true));
assertThat(bean.getIntProperty(), is(equalTo(45)));
assertThat(bean.stringProperty, is(equalTo("haha")));
assertThat(bean.booleanProperty, is(true));
assertThat(bean.intProperty, is(equalTo(45)));
}



private <T> T getBeanOfType(Class<T> beanClass) {
return CDI.current().select(beanClass).get();
}

@Dependent
public static class SimpleValuesBean {

@Inject
@ConfigProperty(name="envconfig.my.string/property")
private String stringProperty;

@Inject
@ConfigProperty(name="envconfig.my.boolean/property")
private boolean booleanProperty;

@Inject
@ConfigProperty(name="envconfig.my.int/property")
private int intProperty;
}
}
Loading

0 comments on commit a6717b5

Please sign in to comment.