org.deephacks.tools4j.config.test.cdi.CdiFeatureTest Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of tools4j-config-tck Show documentation
Show all versions of tools4j-config-tck Show documentation
Functional Tests for Tools4j Config
package org.deephacks.tools4j.config.test.cdi;
import org.deephacks.tools4j.config.ConfigContext;
import org.deephacks.tools4j.config.admin.AdminContext;
import org.deephacks.tools4j.config.model.Bean;
import org.deephacks.tools4j.config.model.Bean.BeanId;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import javax.inject.Inject;
import javax.inject.Singleton;
import static org.deephacks.tools4j.config.test.ConversionUtils.toBean;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
@Singleton
@RunWith(CdiFeatureTestsRunner.class)
public class CdiFeatureTest {
@Inject
private ConfigContext config;
@Inject
private AdminContext admin;
@Inject
private CdiSingletonConfig singleton;
@Before
public void setup() {
// touch get to force injection
singleton.getValue();
}
@Test
public void test_singleton_injection() {
assertThat(singleton.getValue(), is("value"));
}
@Test
public void test_context_injection() {
CdiSingletonConfig config = new CdiSingletonConfig("newvalue");
Bean bean = toBean(config);
admin.create(bean);
admin.set(bean);
BeanId id = BeanId.createSingleton(CdiSingletonConfig.class.getSimpleName());
bean = admin.get(id).get();
assertThat(bean.getValues("value").get(0), is("newvalue"));
config = this.config.get(CdiSingletonConfig.class);
assertThat(config.getValue(), is("newvalue"));
}
}