ReferenceCollection referenceCollection = new MockReferenceCollection();
JavaBeanXmlAttributeBuilder javaBeanXmlAttributeBuilder = new JavaBeanXmlAttributeBuilder();
//this is kind of cheating, we rely on the builder to iterate through existing members of the collection.
referenceCollection.add(javaBeanXmlAttributeBuilder);
Naming naming = new Jsr77Naming();
NamespaceDrivenBuilder gbeanBuilder = new GBeanBuilder(referenceCollection, null);
// ConfigurationBuilder serviceBuilder = new ServiceConfigBuilder(parentEnvironment, null, Collections.singleton(gbeanBuilder), naming);
ClassLoader cl = Thread.currentThread().getContextClassLoader();
final URL plan1 = cl.getResource("services/plan1.xml");
ModuleDocument doc = ModuleDocument.Factory.parse(plan1);
ModuleType plan = doc.getModule();
File outFile = File.createTempFile("foo", "bar");
outFile.delete();
if (!outFile.mkdirs()) {
fail("could not create temp dir");
}
try {
Environment environment = EnvironmentBuilder.buildEnvironment(plan.getEnvironment());
Set<Artifact> repo = new HashSet<Artifact>();
repo.add(Artifact.create("geronimo/foo1/DEV/car"));
repo.add(Artifact.create("geronimo/foo2/DEV/car"));
repo.add(Artifact.create("geronimo/foo3/DEV/car"));
repo.add(Artifact.create("geronimo/foo4/DEV/car"));
ListableRepository mockRepository = new MockRepository(repo);
ArtifactManager artifactManager = new DefaultArtifactManager();
ArtifactResolver artifactResolver = new DefaultArtifactResolver(artifactManager, Collections.singleton(mockRepository), null);
ConfigurationManager configurationManager = new SimpleConfigurationManager(Collections.EMPTY_SET, artifactResolver, Collections.EMPTY_SET);
AbstractName moduleName = naming.createRootName(environment.getConfigId(), "foo", "bar");
DeploymentContext context = new DeploymentContext(outFile, null, environment, moduleName, ConfigurationModuleType.CAR, naming, configurationManager, Collections.singleton(mockRepository));
gbeanBuilder.build(plan, context, context);
Set gbeanNames = context.getGBeanNames();
assertEquals(1, gbeanNames.size());
AbstractName beanName = (AbstractName) gbeanNames.iterator().next();
GBeanData data = context.getGBeanInstance(beanName);
FooBarBean fooBarBean = (FooBarBean) data.getAttribute("fooBarBean");