org.deephacks.tools4j.config.test.bean.BeanManagerGetTests 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.bean;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertThat;
import java.util.List;
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.MockLookup;
import org.junit.Test;
import org.junit.runner.RunWith;
@RunWith(FeatureTestsRunner.class)
public class BeanManagerGetTests {
BeanManager manager = MockLookup.get().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.
Bean grandpa = manager.getEager(grandParentId);
List childs = grandpa.getReferenceNames();
assertThat(childs.size(), is(1));
BeanId childRef = grandpa.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");
}
}