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

org.deephacks.tools4j.config.test.bean.BeanManagerGetTests Maven / Gradle / Ivy

There is a newer version: 0.15.0
Show newest version
package org.deephacks.tools4j.config.test.bean;

import com.google.common.base.Optional;
import org.deephacks.tools4j.config.model.Bean;
import org.deephacks.tools4j.config.model.Bean.BeanId;
import org.deephacks.tools4j.config.spi.BeanManager;
import org.deephacks.tools4j.config.test.FeatureTestsRunner;
import org.deephacks.tools4j.config.test.LookupProxy;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.util.List;

import static org.hamcrest.CoreMatchers.*;
import static org.junit.Assert.*;

@RunWith(FeatureTestsRunner.class)
public class BeanManagerGetTests {
    BeanManager manager = LookupProxy.lookup(BeanManager.class);

    @Test
    public void test_get_eagerly() {
        // add child
        Bean child = Bean.create(BeanId.create("child", "java.lang.String"));
        child.addProperty("property1", "true");
        child.addProperty("property2", "false");
        manager.create(child);

        // add parent that reference child
        Bean parent = Bean.create(BeanId.create("parent", "java.lang.String"));
        parent.addReference("refName", BeanId.create("child", "java.lang.String"));
        parent.addProperty("property1", "prop1");
        parent.addProperty("property2", "prop2");
        manager.create(parent);

        // add grandparent that reference parent
        BeanId grandParentId = BeanId.create("grandparent", "java.lang.String");
        Bean grandparent = Bean.create(grandParentId);
        grandparent.addReference("refName", BeanId.create("parent", "java.lang.String"));
        manager.create(grandparent);

        // query parent and see if bean reference got fetched.
        Optional grandpa = manager.getEager(grandParentId);

        List childs = grandpa.get().getReferenceNames();
        assertThat(childs.size(), is(1));
        BeanId childRef = grandpa.get().getReference(childs.get(0)).get(0);
        Bean childBean = childRef.getBean();
        assertThat(childBean.getId(), is(childBean.getId()));
        assertEquals(childBean.getSingleValue("property1"), "prop1");
        assertEquals(childBean.getSingleValue("property2"), "prop2");

        // parent cool, lets look for children
        childs = childBean.getReferenceNames();
        assertThat(childs.size(), is(1));
        childRef = childBean.getReference(childs.get(0)).get(0);
        childBean = childRef.getBean();

        assertThat(childBean.getId(), is(childBean.getId()));
        assertEquals(childBean.getSingleValue("property1"), "true");
        assertEquals(childBean.getSingleValue("property2"), "false");
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy