AdvertisingMetadataProcessor implements DeploymentProcessor { @Override public void process() { Collection<AnnotationInstance> annos = index.getAnnotations(DotName.createSimple(Advertise.class.getName())); Collection<AnnotationInstance> repeatingAnnos = index.getAnnotations(DotName.createSimple(Advertises.class.getName())); Stream.concat(annos.stream(), repeatingAnnos .stream() .flatMap(anno -> Stream.of(anno.value().asNestedArray()))) .forEach(anno -> advertise(archive, anno)); } @Inject  AdvertisingMetadataProcessor(Archive archive, IndexView index); @Override void process();  }
@Test public void testNoAnnotations() throws IOException { JARArchive archive = ShrinkWrap.create(JARArchive.class); AdvertisingMetadataProcessor processor = new AdvertisingMetadataProcessor(archive, createIndex(archive)); processor.process(); List<String> advertisements = archive.as(TopologyArchive.class).advertisements(); assertThat(advertisements).isEmpty(); }
@Test public void testWithSingleAnnotation() throws IOException { JARArchive archive = ShrinkWrap.create(JARArchive.class); archive.addClass(MyClass.class); AdvertisingMetadataProcessor processor = new AdvertisingMetadataProcessor(archive, createIndex(archive)); processor.process(); List<String> advertisements = archive.as(TopologyArchive.class).advertisements(); assertThat(advertisements).hasSize(1); assertThat(advertisements).contains("foo"); }
@Test public void testWithRepeatingAnnotation() throws IOException { JARArchive archive = ShrinkWrap.create(JARArchive.class); archive.addClass(MyRepeatingClass.class); AdvertisingMetadataProcessor processor = new AdvertisingMetadataProcessor(archive, createIndex(archive)); processor.process(); List<String> advertisements = archive.as(TopologyArchive.class).advertisements(); assertThat(advertisements).hasSize(2); assertThat(advertisements).contains("cheddar"); assertThat(advertisements).contains("gouda"); }