@Test
  public void testNameLookupReturnsAllMatches() throws Exception {
    AddonRegistry registry =
        SimpleContainer.getFurnace(this.getClass().getClassLoader()).getAddonRegistry();
    Imported<PublishedService> instance = registry.getServices(PublishedService.class.getName());
    Assert.assertTrue(instance.isAmbiguous());
    Assert.assertFalse(instance.isUnsatisfied());

    Assert.assertNotNull(instance);
    Iterator<PublishedService> iterator = instance.iterator();
    Assert.assertTrue(iterator.hasNext());
    Object first = iterator.next();
    Assert.assertNotNull(first);
    Assert.assertTrue(iterator.hasNext());
    Assert.assertTrue(iterator.hasNext());
    Object second = iterator.next();
    Assert.assertNotNull(second);
    Assert.assertFalse(iterator.hasNext());

    boolean typeMatchFound = false;
    if (first instanceof PublishedService) typeMatchFound = true;
    if (second instanceof PublishedService) typeMatchFound = true;

    Assert.assertTrue(typeMatchFound);
  }
 @Test(expected = IllegalStateException.class)
 public void testGetWhenAmbiguousThrowsException() throws Exception {
   AddonRegistry registry =
       SimpleContainer.getFurnace(this.getClass().getClassLoader()).getAddonRegistry();
   Imported<PublishedService> instance = registry.getServices(PublishedService.class.getName());
   Assert.assertTrue(instance.isAmbiguous());
   instance.get();
 }
 @Test
 public void testTypedLookupReturnsProperType() throws Exception {
   AddonRegistry registry =
       SimpleContainer.getFurnace(this.getClass().getClassLoader()).getAddonRegistry();
   Imported<PublishedService> instance = registry.getServices(PublishedService.class);
   Assert.assertNotNull(instance);
   PublishedService service = instance.get();
   Assert.assertNotNull(service);
 }
 @Test
 public void testMissingTypedLookupReturnsEmptyInstance() throws Exception {
   AddonRegistry registry =
       SimpleContainer.getFurnace(this.getClass().getClassLoader()).getAddonRegistry();
   Imported<AddonDependencyEntry> instance = registry.getServices(AddonDependencyEntry.class);
   Assert.assertNotNull(instance);
   Assert.assertFalse(instance.isAmbiguous());
   Assert.assertTrue(instance.isUnsatisfied());
 }
 @Test
 public void testAmbiguousSelect() throws Exception {
   AddonRegistry registry =
       SimpleContainer.getFurnace(this.getClass().getClassLoader()).getAddonRegistry();
   Imported<PublishedService> instance = registry.getServices(PublishedService.class.getName());
   Assert.assertTrue(instance.isAmbiguous());
   PublishedService service = instance.selectExact(PublishedService.class);
   Assert.assertNotNull(service);
 }
 @Test
 public void testMissingNamedLookupReturnsEmptyInstance() throws Exception {
   AddonRegistry registry =
       SimpleContainer.getFurnace(this.getClass().getClassLoader()).getAddonRegistry();
   Imported<PublishedService> instance =
       registry.getServices("org.example.blah.NotExistsBadClassThing");
   Assert.assertNotNull(instance);
   Assert.assertFalse(instance.isAmbiguous());
   Assert.assertTrue(instance.isUnsatisfied());
 }
Example #7
0
 @Test
 public void testCreateTempProjectWithBuildSystem() throws Exception {
   ProjectProvider buildSystem = buildSystems.get();
   try {
     Project project = projectFactory.createTempProject(buildSystem);
     Assert.assertNotNull(project);
   } finally {
     buildSystems.release(buildSystem);
   }
 }
 @Test
 public void testTypedLookupCanBeIterated() throws Exception {
   AddonRegistry registry =
       SimpleContainer.getFurnace(this.getClass().getClassLoader()).getAddonRegistry();
   Imported<PublishedService> instance = registry.getServices(PublishedService.class);
   Assert.assertFalse(instance.isAmbiguous());
   Assert.assertFalse(instance.isUnsatisfied());
   Iterator<PublishedService> iterator = instance.iterator();
   Assert.assertTrue(iterator.hasNext());
   Assert.assertNotNull(iterator.next());
   Assert.assertFalse(iterator.hasNext());
 }
Example #9
0
 @Test
 public void testCreateTempProjectWithBuildSystemAndFacets() {
   ProjectProvider buildSystem = buildSystems.get();
   try {
     Project project =
         projectFactory.createTempProject(
             buildSystem, Arrays.<Class<? extends ProjectFacet>>asList(WebResourcesFacet.class));
     Assert.assertNotNull(project);
     Assert.assertTrue(project.hasFacet(WebResourcesFacet.class));
   } finally {
     buildSystems.release(buildSystem);
   }
 }
Example #10
0
  @Test
  public void testContainsProjectWithBuildSystem() {
    ProjectProvider buildSystem = buildSystems.get();
    try {
      Project project = projectFactory.createTempProject(buildSystem);
      Assert.assertNotNull(project);
      Resource<?> projectRoot = project.getRoot();
      Assert.assertTrue(projectFactory.containsProject(projectRoot, projectRoot, buildSystem));
      Assert.assertTrue(
          projectFactory.containsProject(projectRoot, projectRoot.getChild("src"), buildSystem));

      projectRoot.delete(true);
      Assert.assertFalse(projectFactory.containsProject(projectRoot, projectRoot, buildSystem));
    } finally {
      buildSystems.release(buildSystem);
    }
  }
Example #11
0
 @Override
 public Iterable<UICommand> getCommands() {
   Set<UICommand> result = new HashSet<>();
   synchronized (this) {
     Imported<CommandProvider> instances = registry.getServices(CommandProvider.class);
     for (CommandProvider provider : instances) {
       Iterable<UICommand> commands = provider.getCommands();
       Iterator<UICommand> iterator = commands.iterator();
       while (iterator.hasNext()) {
         try {
           UICommand command = iterator.next();
           if (!(command instanceof UIWizardStep)) {
             result.add(command);
           }
         } catch (Exception e) {
           log.log(Level.SEVERE, "Error while retrieving command instance", e);
         }
       }
       instances.release(provider);
     }
   }
   return result;
 }
Example #12
0
 private void initConfigureMetadata() {
   configureMetadata.setDefaultValue(Boolean.FALSE);
   if (metaModelFacets.isUnsatisfied()) {
     configureMetadata.setEnabled(false);
   }
 }