All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.deephacks.tools4j.config.test.cdi.CdiFeatureTest Maven / Gradle / Ivy

There is a newer version: 0.15.0
Show newest version
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"));
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy