@Test public void testTagsFromSpec() throws Exception { MyEnricher enricher = app.enrichers().add(EnricherSpec.create(MyEnricher.class).tag(99).uniqueTag("x")); assertEquals(enricher.tags().getTags(), MutableSet.of("x", 99)); assertEquals(enricher.getUniqueTag(), "x"); }
@Test public void testSameUniqueTagEnricherNotAddedTwice() throws Exception { MyEnricher enricher1 = app.enrichers().add(EnricherSpec.create(MyEnricher.class).tag(99).uniqueTag("x")); MyEnricher enricher2 = app.enrichers().add(EnricherSpec.create(MyEnricher.class).tag(94).uniqueTag("x")); // the more recent one should dominate assertEquals(app.enrichers().asList(), ImmutableList.of(enricher2)); Enricher enricher = Iterables.getOnlyElement(app.enrichers()); Assert.assertTrue(enricher.tags().containsTag(94)); Assert.assertFalse(enricher.tags().containsTag(99)); }
@Test public void testRestoresConfig() throws Exception { origApp.enrichers().add(EnricherSpec.create(MyEnricher.class) .displayName("My Enricher") .uniqueTag("tagU") .tag("tag1").tag("tag2") .configure(MyEnricher.MY_CONFIG_WITH_SETFROMFLAG_NO_SHORT_NAME, "myVal for with setFromFlag noShortName") .configure(MyEnricher.MY_CONFIG_WITH_SETFROMFLAG_WITH_SHORT_NAME, "myVal for setFromFlag withShortName") .configure(MyEnricher.MY_CONFIG_WITHOUT_SETFROMFLAG, "myVal for witout setFromFlag")); newApp = rebind(); MyEnricher newEnricher = (MyEnricher) Iterables.getOnlyElement(newApp.enrichers()); assertEquals(newEnricher.getDisplayName(), "My Enricher"); assertEquals(newEnricher.getUniqueTag(), "tagU"); assertEquals(newEnricher.tags().getTags(), MutableSet.of("tagU", "tag1", "tag2")); assertEquals(newEnricher.getConfig(MyEnricher.MY_CONFIG_WITH_SETFROMFLAG_NO_SHORT_NAME), "myVal for with setFromFlag noShortName"); assertEquals(newEnricher.getConfig(MyEnricher.MY_CONFIG_WITH_SETFROMFLAG_WITH_SHORT_NAME), "myVal for setFromFlag withShortName"); assertEquals(newEnricher.getConfig(MyEnricher.MY_CONFIG_WITHOUT_SETFROMFLAG), "myVal for witout setFromFlag"); }
@Override public void onManagementStarting() { super.onManagementStarted(); enrichers().add(EnricherSpec.create(MyEnricher.class).uniqueTag("y").tag(Identifiers.makeRandomId(8))); } @Override
@Override public void onManagementStarted() { super.onManagementStarted(); enrichers().add(EnricherSpec.create(MyEnricher.class).uniqueTag("z").tag(Identifiers.makeRandomId(8))); // all the enrichers above should not be added on rebind, but this one will be: enrichers().add(EnricherSpec.create(MyEnricher.class).uniqueTag( Identifiers.makeRandomId(8) ).tag(Identifiers.makeRandomId(8))); } }
@Override protected void initEnrichers() { // don't add default ones enrichers().add(EnricherSpec.create(MyEnricher.class).uniqueTag("x").tag(Identifiers.makeRandomId(8))); enrichers().add(EnricherSpec.create(MyEnricher.class)); } @Override