ProcessHeadersTransformer implements InstrumentActionTransformer { @Override public String convertToRuleAction(InstrumentAction action) { ProcessHeaders phAction = (ProcessHeaders) action; StringBuilder builder = new StringBuilder(64); builder.append("collector()."); if (phAction.getDirection() == Direction.In) { builder.append("processIn("); } else { builder.append("processOut("); } builder.append("getRuleName(),"); if (phAction.getOriginalType() != null) { builder.append("getHeaders(\""); builder.append(phAction.getOriginalType()); builder.append("\","); } builder.append(phAction.getHeadersExpression()); if (phAction.getOriginalType() != null) { builder.append(")"); } builder.append(",null)"); return builder.toString(); }  @Override Class<? extends InstrumentAction> getActionType(); @Override String convertToRuleAction(InstrumentAction action);  }
@Test public void testConvertToRuleActionIn() { ProcessHeaders im = new ProcessHeaders(); im.setHeadersExpression("headers"); ProcessHeadersTransformer transformer = new ProcessHeadersTransformer(); String transformed = transformer.convertToRuleAction(im); String expected = ACTION_PREFIX + "processIn(getRuleName(),headers,null)"; assertEquals(expected, transformed); }
@Test public void testConvertToRuleActionInWithOriginalType() { ProcessHeaders im = new ProcessHeaders(); im.setHeadersExpression("headers"); im.setOriginalType("org.Type"); ProcessHeadersTransformer transformer = new ProcessHeadersTransformer(); String transformed = transformer.convertToRuleAction(im); String expected = ACTION_PREFIX + "processIn(getRuleName(),getHeaders(\"org.Type\",headers),null)"; assertEquals(expected, transformed); }
@Test public void testConvertToRuleActionOut() { ProcessHeaders im = new ProcessHeaders(); im.setDirection(Direction.Out); im.setHeadersExpression("headers"); ProcessHeadersTransformer transformer = new ProcessHeadersTransformer(); String transformed = transformer.convertToRuleAction(im); String expected = ACTION_PREFIX + "processOut(getRuleName(),headers,null)"; assertEquals(expected, transformed); }
@Test public void testConvertToRuleActionOutWithOriginalType() { ProcessHeaders im = new ProcessHeaders(); im.setDirection(Direction.Out); im.setHeadersExpression("headers"); im.setOriginalType("org.Type"); ProcessHeadersTransformer transformer = new ProcessHeadersTransformer(); String transformed = transformer.convertToRuleAction(im); String expected = ACTION_PREFIX + "processOut(getRuleName(),getHeaders(\"org.Type\",headers),null)"; assertEquals(expected, transformed); }