ProcessContentTransformer implements InstrumentActionTransformer { @Override public String convertToRuleAction(InstrumentAction action) { ProcessContent pcAction = (ProcessContent) action; StringBuilder builder = new StringBuilder(128); builder.append("collector()."); if (pcAction.getDirection() == Direction.In) { builder.append("processIn("); } else { builder.append("processOut("); } builder.append("getRuleName(),null,createArrayBuilder()"); for (String expr : pcAction.getValueExpressions()) { builder.append(".add("); builder.append(expr); builder.append(')'); } builder.append(".get()"); builder.append(")"); return builder.toString(); }  @Override Class<? extends InstrumentAction> getActionType(); @Override String convertToRuleAction(InstrumentAction action);  }
@Test public void testConvertToRuleActionIn() { ProcessContent im = new ProcessContent(); im.getValueExpressions().add("$1"); im.getValueExpressions().add("$2"); ProcessContentTransformer transformer = new ProcessContentTransformer(); String transformed = transformer.convertToRuleAction(im); String expected = ACTION_PREFIX + "processIn(getRuleName(),null,createArrayBuilder().add($1).add($2).get())"; assertEquals(expected, transformed); }
@Test public void testConvertToRuleActionOut() { ProcessContent im = new ProcessContent(); im.setDirection(Direction.Out); im.getValueExpressions().add("$1"); im.getValueExpressions().add("$2"); ProcessContentTransformer transformer = new ProcessContentTransformer(); String transformed = transformer.convertToRuleAction(im); String expected = ACTION_PREFIX + "processOut(getRuleName(),null,createArrayBuilder().add($1).add($2).get())"; assertEquals(expected, transformed); }