@Test void testEvaluateRef() { EntityType refEntityType = mock(EntityType.class); Attribute refAttribute = when(mock(Attribute.class).getDataType()).thenReturn(STRING).getMock(); when(refEntityType.getAttribute("refAttr")).thenReturn(refAttribute); Entity refEntity = mock(Entity.class); when(refEntity.getEntityType()).thenReturn(refEntityType); when(refEntity.getString("refAttr")).thenReturn("value"); when(expressionAttribute.getExpression()).thenReturn("{\"template\":\"my {{attr.refAttr}}\"}"); Attribute attribute = when(mock(Attribute.class).getDataType()).thenReturn(XREF).getMock(); when(attribute.hasRefEntity()).thenReturn(true); when(attribute.getRefEntity()).thenReturn(refEntityType); when(entityType.getAttribute("attr")).thenReturn(attribute); Entity entity = when(mock(Entity.class).getEntity("attr")).thenReturn(refEntity).getMock(); when(entity.getEntityType()).thenReturn(entityType); assertEquals("my value", templateExpressionEvaluator.evaluate(entity)); }
@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);  }