String url = myClassLoader.getResource("test.txt").toString();
url = url.substring(0, url.length()-8);
// Contribute the SCA contribution
TestModelResolver myResolver = new TestModelResolver(myClassLoader);
ContributionService contributionService = domain.getContributionService();
Contribution contribution = contributionService.contribute("http://test/contribution", new URL(url), myResolver, false);
assertNotNull(contribution);
// Decide which SCA composite I want to deploy
Composite myComposite = myResolver.getComposite(new QName("http://test", "test"));
// Add the deployable composite to the domain
domain.getDomainComposite().getIncludes().add(myComposite);
domain.buildComposite(myComposite);
// Start the composite
domain.getCompositeActivator().activate(myComposite);
domain.getCompositeActivator().start(myComposite);
// At this point the domain contains my contribution, my composite and
// it's started, my application code can start using it
ComponentManager componentManager = domain.getComponentManager();
assertEquals(1, componentManager.getComponentNames().size());
assertEquals("TestServiceComponent", componentManager.getComponentNames().iterator().next());
Component component = componentManager.getComponent("TestServiceComponent");
assertNotNull(component);
assertEquals("TestServiceComponent", component.getName());
MyComponentListener cl = new MyComponentListener();
componentManager.addComponentListener(cl);
assertTrue(componentManager.isComponentStarted("TestServiceComponent"));
assertFalse(cl.stopCalled);
componentManager.stopComponent("TestServiceComponent");
assertTrue(cl.stopCalled);
assertFalse(componentManager.isComponentStarted("TestServiceComponent"));
assertFalse(cl.startCalled);
componentManager.startComponent("TestServiceComponent");
assertTrue(cl.startCalled);
assertTrue(componentManager.isComponentStarted("TestServiceComponent"));
// Stop my composite
domain.getCompositeActivator().stop(myComposite);
domain.getCompositeActivator().deactivate(myComposite);
// Remove my composite
domain.getDomainComposite().getIncludes().remove(myComposite);
// Remove my contribution
contributionService.remove("http://test/contribution");
// Stop the domain
domain.stop();
}