List of usage examples for org.apache.commons.text ExtendedMessageFormat ExtendedMessageFormat
public ExtendedMessageFormat(final String pattern)
From source file:com.nextdoor.bender.operation.substitution.formatted.FormattedSubstitutionFactory.java
@Override public void setConf(AbstractConfig config) { this.config = (FormattedSubstitutionConfig) config; this.format = new ExtendedMessageFormat(this.config.getFormat()); }
From source file:com.nextdoor.bender.operation.substitution.FormattedSubstitutionTest.java
@Test public void testStringSubKnown() throws FieldNotFoundException { Variable.FieldVariable v = new Variable.FieldVariable(); v.setFailSrcNotFound(true);/*from www .j a v a 2s. c o m*/ v.setSrcFields(Arrays.asList("foo")); ArrayList<Substitution> substitutions = new ArrayList<Substitution>(); substitutions.add( new FormattedSubstitution("bar", new ExtendedMessageFormat("foo = {0}"), Arrays.asList(v), true)); DummpyMapEvent devent = new DummpyMapEvent(); devent.setField("foo", "1234"); InternalEvent ievent = new InternalEvent("", null, 0); ievent.setEventObj(devent); SubstitutionOperation op = new SubstitutionOperation(substitutions); op.perform(ievent); assertEquals(2, devent.payload.size()); assertEquals("foo = 1234", devent.getField("bar")); assertEquals("1234", devent.getField("foo")); }
From source file:com.nextdoor.bender.operation.substitution.FormattedSubstitutionTest.java
@Test public void testStringReplace() throws FieldNotFoundException { Variable.FieldVariable v = new Variable.FieldVariable(); v.setFailSrcNotFound(true);/*from www . j av a 2 s .c om*/ v.setSrcFields(Arrays.asList("foo")); ArrayList<Substitution> substitutions = new ArrayList<Substitution>(); substitutions.add( new FormattedSubstitution("foo", new ExtendedMessageFormat("foo = {0}"), Arrays.asList(v), true)); DummpyMapEvent devent = new DummpyMapEvent(); devent.setField("foo", "1234"); InternalEvent ievent = new InternalEvent("", null, 0); ievent.setEventObj(devent); SubstitutionOperation op = new SubstitutionOperation(substitutions); op.perform(ievent); assertEquals(1, devent.payload.size()); assertEquals("foo = 1234", devent.getField("foo")); }
From source file:com.nextdoor.bender.operation.substitution.FormattedSubstitutionTest.java
@Test public void testStringSubNumberKnown() throws FieldNotFoundException { Variable.FieldVariable v = new Variable.FieldVariable(); v.setFailSrcNotFound(true);/*from w ww . j av a 2s . co m*/ v.setSrcFields(Arrays.asList("foo")); ArrayList<Substitution> substitutions = new ArrayList<Substitution>(); substitutions.add(new FormattedSubstitution("bar", new ExtendedMessageFormat("number = {0}"), Arrays.asList(v), true)); DummpyMapEvent devent = new DummpyMapEvent(); devent.setField("foo", new Float(1.234f)); InternalEvent ievent = new InternalEvent("", null, 0); ievent.setEventObj(devent); SubstitutionOperation op = new SubstitutionOperation(substitutions); op.perform(ievent); assertEquals(2, devent.payload.size()); assertEquals("number = 1.234", devent.getField("bar")); }
From source file:com.nextdoor.bender.operation.substitution.FormattedSubstitutionTest.java
@Test public void testStringSubUnknown() throws FieldNotFoundException { Variable.FieldVariable v = new Variable.FieldVariable(); v.setFailSrcNotFound(false);//from www . j a va 2s . co m v.setSrcFields(Arrays.asList("baz")); ArrayList<Substitution> substitutions = new ArrayList<Substitution>(); substitutions.add( new FormattedSubstitution("bar", new ExtendedMessageFormat("foo = {0}"), Arrays.asList(v), true)); DummpyMapEvent devent = new DummpyMapEvent(); devent.setField("foo", "1234"); InternalEvent ievent = new InternalEvent("", null, 0); ievent.setEventObj(devent); SubstitutionOperation op = new SubstitutionOperation(substitutions); op.perform(ievent); assertEquals(2, devent.payload.size()); assertEquals("foo = null", devent.getField("bar")); assertEquals("1234", devent.getField("foo")); }
From source file:com.nextdoor.bender.operation.substitution.FormattedSubstitutionTest.java
@Test(expected = OperationException.class) public void testStringSubUnknownFail() throws FieldNotFoundException { Variable.FieldVariable v = new Variable.FieldVariable(); v.setFailSrcNotFound(true);//from ww w.ja v a 2s . c om v.setSrcFields(Arrays.asList("baz")); ArrayList<Substitution> substitutions = new ArrayList<Substitution>(); substitutions.add( new FormattedSubstitution("bar", new ExtendedMessageFormat("foo = {0}"), Arrays.asList(v), true)); DummpyMapEvent devent = new DummpyMapEvent(); devent.setField("foo", "1234"); InternalEvent ievent = new InternalEvent("", null, 0); ievent.setEventObj(devent); SubstitutionOperation op = new SubstitutionOperation(substitutions); op.perform(ievent); }
From source file:com.nextdoor.bender.operation.substitution.FormattedSubstitutionTest.java
@Test public void testStringSubRemove() throws FieldNotFoundException { Variable.FieldVariable v = new Variable.FieldVariable(); v.setFailSrcNotFound(true);//from ww w.j ava2s.c o m v.setRemoveSrcField(true); v.setSrcFields(Arrays.asList("foo")); ArrayList<Substitution> substitutions = new ArrayList<Substitution>(); substitutions.add( new FormattedSubstitution("bar", new ExtendedMessageFormat("foo = {0}"), Arrays.asList(v), true)); DummpyMapEvent devent = new DummpyMapEvent(); devent.setField("foo", "1234"); InternalEvent ievent = new InternalEvent("", null, 0); ievent.setEventObj(devent); SubstitutionOperation op = new SubstitutionOperation(substitutions); op.perform(ievent); assertEquals(1, devent.payload.size()); assertEquals("foo = 1234", devent.getField("bar")); }
From source file:com.nextdoor.bender.operation.substitution.FormattedSubstitutionTest.java
@Test public void testStringSubStatic() throws FieldNotFoundException { Variable.StaticVariable v = new Variable.StaticVariable(); v.setValue("1234"); ArrayList<Substitution> substitutions = new ArrayList<Substitution>(); substitutions.add(new FormattedSubstitution("bar", new ExtendedMessageFormat("static = {0}"), Arrays.asList(v), true)); DummpyMapEvent devent = new DummpyMapEvent(); InternalEvent ievent = new InternalEvent("", null, 0); ievent.setEventObj(devent);/* w ww . j a va 2 s . co m*/ SubstitutionOperation op = new SubstitutionOperation(substitutions); op.perform(ievent); assertEquals(1, devent.payload.size()); assertEquals("static = 1234", devent.getField("bar")); }