@Test void testEvaluateRefAttributeMissing() { when(expressionAttribute.getExpression()).thenReturn("{\"template\":\"my {{attr}}\"}"); Attribute attribute = when(mock(Attribute.class).getDataType()).thenReturn(XREF).getMock(); EntityType refEntityType = mock(EntityType.class); when(attribute.hasRefEntity()).thenReturn(true); when(attribute.getRefEntity()).thenReturn(refEntityType); when(entityType.getAttribute("attr")).thenReturn(attribute); Exception exception = assertThrows( TemplateExpressionMissingTagException.class, () -> templateExpressionEvaluator.evaluate(mock(Entity.class))); assertThat(exception.getMessage()) .containsPattern("expression:\\{\"template\":\"my \\{\\{attr\\}\\}\"\\} tag:attr"); }
@Override public Object evaluate(Entity entity) { initTemplate(); Map<String, Object> tagValues = getTemplateTagValue(entity); try { return template.apply(Context.newContext(tagValues)); } catch (IOException e) { throw new TemplateExpressionException(attribute, e); } }
TemplateExpressionEvaluator implements ExpressionEvaluator { @Override public Object evaluate(Entity entity) { initTemplate(); Map<String, Object> tagValues = getTemplateTagValue(entity); try { return template.apply(Context.newContext(tagValues)); } catch (IOException e) { throw new TemplateExpressionException(attribute, e); } } }
TemplateExpressionEvaluator implements ExpressionEvaluator { @Override public Object evaluate(Entity entity) { initTemplate(); Map<String, Object> tagValues = getTemplateTagValue(entity); try { return template.apply(Context.newContext(tagValues)); } catch (IOException e) { throw new TemplateExpressionException(attribute, e); } } TemplateExpressionEvaluator(Attribute attribute, EntityType entityType); }
TemplateExpressionEvaluator implements ExpressionEvaluator { @Override public Object evaluate(Entity entity) { initTemplate(); Map<String, Object> tagValues = getTemplateTagValue(entity); try { return template.apply(Context.newContext(tagValues)); } catch (IOException e) { throw new TemplateExpressionException(attribute, e); } } TemplateExpressionEvaluator(Attribute attribute, EntityType entityType); @Override Object evaluate(Entity entity); static Template getTemplate(Attribute attribute); }
TemplateExpressionEvaluator implements ExpressionEvaluator { @Override public Object evaluate(Entity entity) { initTemplate(); Map<String, Object> tagValues = getTemplateTagValue(entity); try { return template.apply(Context.newContext(tagValues)); } catch (IOException e) { throw new TemplateExpressionException(attribute, e); } } TemplateExpressionEvaluator(Attribute attribute, EntityType entityType); @Override Object evaluate(Entity entity); static Template getTemplate(Attribute attribute);  }