Bean implements BeanEnricher, XmlWriter, Comparable<Bean> { void resolveDependency(BlueprintRegistry blueprintRegistry) { resolveArguments(blueprintRegistry); resolveFields(blueprintRegistry); resolveMethods(blueprintRegistry); } Bean(Class<?> clazz, ContextEnricher contextEnricher); @Override void addAttribute(String key, String value); @Override void addBeanContentWriter(String id, XmlWriter blueprintWriter); @Override void write(XMLStreamWriter writer); @Override int compareTo(Bean o);  }
@Test public void testParseMyBean1() { Bean bean = new Bean(MyBean1.class, blueprint); bean.resolveDependency(blueprint); assertEquals(MyBean1.class, bean.clazz); assertEquals("myBean1", bean.id); assertEquals(2, getPersistenceFields(bean).size()); assertEquals(Sets.newHashSet("em", "emf"), getPersistenceFields(bean)); assertEquals(1, bean.properties.size()); assertEquals("singleton", bean.attributes.get("scope")); Property prop = bean.properties.iterator().next(); assertEquals("bean2", prop.name); assertEquals("serviceA", prop.ref); Set<TransactionalDef> expectedTxs = Sets.newHashSet(new TransactionalDef("*", "RequiresNew"), new TransactionalDef("txNotSupported", "NotSupported"), new TransactionalDef("txMandatory", "Mandatory"), new TransactionalDef("txNever", "Never"), new TransactionalDef("txRequired", "Required"), new TransactionalDef("txOverridenWithRequiresNew", "RequiresNew"), new TransactionalDef("txSupports", "Supports")); assertEquals(expectedTxs, getTransactionalDefs(bean)); }
@Test public void testParseMyBean3() { Bean bean = new Bean(MyBean3.class, blueprint); bean.resolveDependency(blueprint); assertEquals(MyBean3.class, bean.clazz); assertEquals("myBean3", bean.id); assertEquals("There should be no persistence fields", 0, getPersistenceFields(bean).size()); assertEquals(5, bean.properties.size()); assertEquals("prototype", bean.attributes.get("scope")); Set<TransactionalDef> expectedTxs = Sets.newHashSet(new TransactionalDef("*", "RequiresNew"), new TransactionalDef("txNotSupported", "NotSupported"), new TransactionalDef("txMandatory", "Mandatory"), new TransactionalDef("txNever", "Never"), new TransactionalDef("txRequired", "Required"), new TransactionalDef("txRequiresNew", "RequiresNew"), new TransactionalDef("txSupports", "Supports")); assertEquals(expectedTxs, getTransactionalDefs(bean)); }
@Test public void testParseNamedBean() { Bean bean = new Bean(ServiceAImpl1.class, blueprint); bean.resolveDependency(blueprint); String definedName = ServiceAImpl1.class.getAnnotation(Named.class).value(); assertEquals("my1", definedName); assertEquals("Name should be defined using @Named", definedName, bean.id); assertEquals("There should be no persistence fields", 0, getPersistenceFields(bean).size()); assertTrue("There should be no transaction definition", getTransactionalDefs(bean).isEmpty()); assertEquals("There should be no properties", 0, bean.properties.size()); assertEquals("prototype", bean.attributes.get("scope")); }
@Test public void testBlueprintBundleContext() { Bean bean = new Bean(MyBean4.class, blueprint); bean.resolveDependency(blueprint); Property bcProp = bean.properties.iterator().next(); assertEquals("bundleContext", bcProp.name); assertEquals("blueprintBundleContext", bcProp.ref); assertEquals("singleton", bean.attributes.get("scope")); Set<TransactionalDef> expectedTxs = Sets.newHashSet(new TransactionalDef("txWithoutClassAnnotation", "Supports")); assertEquals(expectedTxs, getTransactionalDefs(bean)); }